Explain Call by Value in C language ?



Explain Call by Value in C language ?

Call by value

  • In call by value, original value is not modified.
  • In call by value, value being passed to the function is locally stored by the function parameter in stack memory location. If you change the value of function parameter, it is changed for the current function only.
  • It will not change the value of variable inside the caller method such as main().

Sample Code

#include<stdio.h>
void change(int num) 
{    
    printf("Before adding value inside function num=%d \n",num);    
    num=num+100;    
    printf("After adding value inside function num=%d \n", num);    
}    
int main() 
{    
    int x=100;    
    printf("Before function call x=%d \n", x);    
    change(x);//passing value in function    
    printf("After function call x=%d \n", x);    
    return 0;  
}  

Output

Before function call x=100 
Before adding value inside function num=100 
After adding value inside function num=200 
After function call x=100 

Related Searches to Explain Call by Value in C language ?