Actual and Formal Arguments - Return function - Advantage of functions | Coding classpoint

Actual argument 



The arguments which are mentioned or used inside the function call is knows as actual argument and these are the original values and copy of these are actually sent to the called function.

It can be written as constant, expression or any function call like

Function (x); 

Function (20, 30); 

Function (a*b, c*d); 

Function(2,3,sum(a, b));

Formal Arguments 

The arguments which are mentioned in function definition are called formal arguments or dummy arguments.

These arguments are used to just hold the copied of the values that are sent by the calling function through the function call. 

These arguments are like other local variables which are created when the function call starts and destroyed when the function ends. 

The basic difference between the formal argument and the actual argument are

1) The formal argument are declared inside the parenthesis where as the local variable declared at the beginning of the function block. 

2) The formal argument are automatically initialized when the copy of actual arguments are passed while other local variable are assigned values through the statements. 

Order number and type of actual arguments in the function call should be match with the order number and type of the formal arguments.

Return type 

It is used to return value to the calling function. It can be used in two way as 

return 

Or 

return(expression); 

Ex: 

return (a); 

return (a*b); 

return (a*b+c);

Here the 1st return statement used to terminate the function without returning any value 

Ex: /*summation of two values*/ 

int sum (int a1, int a2); 

 main()

 int a,b; 

 printf(“enter two no”);

 scanf(“%d%d”,&a,&b);

 int S=sum(a,b);

 printf(“summation is = %d”,s); 

 }

 int sum(intx1,int y1) 

 {

 int z=x1+y1;

 Return z;

 } 

Advantage of function 

By using function large and difficult program can be divided in to sub programs and solved. When we want to perform some task repeatedly or some code is to be used more than once at different place in the program, then function avoids this repeatition or rewritten over and over. 

Due to reducing size, modular function it is easy to modify and test.

Notes:

C program is a collection of one or more function. 

A function is get called when function is followed by the semicolon. 

A function is defined when a function name followed by a pair of curly braces

Any function can be called by another function even main() can be called by other function.

main() 

function1() 

function1() 

{ Statement; 

function2; 

function 2() 

So every function in a program must be called directly or indirectly by the main() function. A function can be called any number of times. 

A function can call itself again and again and this process is called recursion. 

A function can be called from other function but a function can’t be defined in another function 


Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.