Anda di halaman 1dari 15

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH
Name : Murali Krishna Chintala
Designation : Lecturer in CME
Branch : Computer Engineering
Institute : SUVR & SR GPW, Ethamukkala
Year/ Semester : III Semester
Subject Name : UNIX & C
Subject Code : CM – 304
Topic : Understand Modular Programming
Duration : 50 Min
Sub Topic : Function call techniques
Teaching Aids : PPT, Animations
CM304.62 1
Objective

On completion of this period, you would be able to

• Understand Formal parameters,Actual parameters.

• Understand calling a function.

CM304.62 2
Function parameters

• Arguments in the function call are called


Actual parameters.

• Arguments appear in the function definition


are called Formal parameters.

CM304.62 3
Calling a function

• A function can be called by

- It’s name,

- Followed by list of arguments,

- Separated by commas and enclosed in


parenthesis

CM304.62 4
Calling a function
Contd..

• There will be one actual parameter for each


formal parameter.

• Data type of actual and formal parameters


should be same.

• Names of actual and formal parameters can


be same or different.

CM304.62 5
Calling a function
contd..

Examples:-
main()
{
int a,b,c;
--------
max(a,b,c);/* a,b,c are actual parameters*/
--------
}
CM304.62 6
Calling a function
contd..
Example:-1
int max(int x, int y, int z) /* x,y,z are formal
parameters*/
{
------
------
}

• The values of actual parameters are copied into formal


parameters.
• a,b,c values are given to x,y,z.

CM304.62 7
Calling a function
contd..

• When the compiler encounters a function call


control is transferred to the calling program.

• After the execution of the function program the


control is transferred back to the main program
using the return statement.

CM304.62 8
Calling a function
contd..
Example:-2
#include<stdio.h>
main()
{
int product = mul(10,10);
printf(“The result is:%d”, product);
}
int mul(int i, int j)
{
return(i*j);
}
CM304.62 9
Summary
In this class, you have learnt..

• Arguments appear in the function definition are called


formal parameters.
• Arguments in the function call are called actual
parameters.
• Formal parameters and actual parameters should be
same in number and type.
• In case of function call control is transferred to the
function program and after it’s execution control is
transferred back to the main program using return
statement.

CM304.62 10
Quiz

1. Data types of both formal and actual parameters


should be..
a) Same

b) Different

c) None

CM304.62 11
Quiz

1. Data types of both formal and actual parameters


should be..
a) Same

b) Different

c) None

CM304.62 12
Quiz
2.The ratio between formal and actual parameters
is..

a) 1:1

b) 1:2

c) Many

CM304.62 13
Quiz

2. The ratio between formal and actual parameters


is..

a) 1:1

b) 1:2

c) Many

CM304.62 14
Frequently Asked Questions

1. Define function.Explain about function


prototypes?
(April 2007)

CM304.62 15