This program defines a function named func which has two parameters, a and b of type int. Within its body, this function first prints these parameter values, initializes them to 30 and prints them again. The main function declares two variables, a and b of type int. It first prints the values of these variables and then calls the function func with variables a and b as its arguments. Finally, the main function prints the values of variables a and b again.
Observe from output lines 2 and 3 that the values of variables a and b are passed to the function and are then initialized to 30. However, the values of variables a and b in the main function are unaffected after the function call. This is expected, as function func uses the default call by value mechanism, making a and b input-only parameters. Also note that although the function parameters and the argument variables have same name, they are different entities, and modifying the function parameters does not affect the argument variables.
void func(int a, int b);
void main ()
int a = 10, b = 20;
printf("In main(), before function call : a = %d b =%d\n",a,b);
printf("In main(), after function call : a = %d b = %d\n",a,b);
void func(int a, int b)
printf("In func(), before initialization: a= %d b =%d\n",a,b);
a = b = 30;
printf("In func(), after initialization : a %d b =%d\n",a,b);