Call By Value and Call By Reference in C

Call By Value and Call By Reference in C


We can observe that the address of a in the main function and the address of a in print function are different.

So, if we change the value of a in print function, it will not affect the value of a in the main function.

 

/*
  * Program  : Call by value example
  * Language : C
  */

 #include<stdio.h>

 //set the argument value to 0
 void set(int a)
 {
     a = 0;
     printf("Set : In set function a = %d\n",a);
 }

 int main()
 {
     int a = 10;

     printf("Main : Before calling set function a = %d\n",a);

     set(a);

     printf("Main : After calling set function a = %d\n",a);

     return 0;
 }