Header Ads Widget

Function Arguments in C Programming

 When calling function sends some value to called function, these values are called arguments or parameters.

Actual arguments : The arguments which are mentioned in function call are known as actual arguments. The actual arguments can be written in the form of variables, constants, expressions or any other function call that returns value. Examples :

 func (n);

func (2, 3, 4);

func ( 1, 3, sub (a, b)); etc.

Formal arguments : The name of arguments which are mentioned in function definition are called formal arguments. They are used to hold the values that are sent by calling function.

int sum ( int a, int b, int c)   /* Here a, b, c are formal arguments*/

{

........

........

}

The type, order and number of actual and formal arguments must always be same.

Look at the following program:

#include <stdio.h>

int add ( int a, int b);

int main ( )

{

int x, y, sum;

printf(" Enter Numbers :");

scanf("%d %d", &x, &y);

sum = add(x, y);       /* Here x, y are actual arguments*/

printf("Sum= %d", sum);

return 0;

}

int add( int a, int b)   /* Here a, b are formal arguments*/

{

int s;

s = a + b;

return s;

}

Instead of using different variable names a, b in formal arguments we can also use variable names same  as mentioned in actual arguments. The compiler will still treat them as different variables because  they are in different functions. 


Post a Comment

0 Comments