C Language

Function Parameters

In C Language by Baqir AliLeave a Comment

Variables declared in the function header are known as a parameters. The variables passed to a function when it is called are known as the function arguments.

The number, order and type of parameters in the parameter list of a function definition and the function call arguments must be identical.

The call to the function add has two variables (arguments) enclosed in the parentheses, x and y.

  • Therefore the values of the variables x and y will be passed from main to add.
  • At the location of the call to add, the value of x is 4 and the value of y is 20.
  • So function add receives the values 4 and 20.

Consider a function definition of the form:

int add(int a, int b) 

What would happen if the function were called with two doubles instead of two integers?

 double x=4.2, y=20.4;
 int z;
 z = add(x,y); 

The values of x any y would be converted to integers! The result of the function would be that

z = 24

Leave a Comment