There are two types of arguments/parameters
- Actual parameters
- Formal parameters
Actual parameters :
Are parameters that appear in function calls.
Syntax :
Function_name(actual parameters)
Formal parameters :
Are parameters that appear in function declarations.
Syntax :
return_type function_name(formal parameters)
Example of actual parameter and formal parameter :
#include <stdio.h>
/* function declaration */
int sum(int num1, int num2);
int main ()
{
/* local variable definition */
int a = 10;
int b = 20;
int s;
/* calling a function to get sum of the numbers */
s = sum(a, b); //Actual Parameter
printf( "Sum of the numbers is : %d\n", s);
return 0;
}
/* function returning the sum of the two numbers */
int sum(int num1, int num2) //Formal Parameter
{
/* local variable declaration */
int result;
result = num1 + num2;
return result;
}
Output :
Sum of the numbers is : 30
Explanation :
In calling function - sum(a,b), a and b are actual parameters.
And parameters in function definition - int sum(int num1, int num2), num1 and num2 are formal parameters.
And parameters in function definition - int sum(int num1, int num2), num1 and num2 are formal parameters.
NOTE :
- Formal parameters are always variables.
- Actual parameters need not have to be variables. You can use variables, numbers, expressions, or even function calls as actual parameters.
No comments:
Post a Comment