Call By Value


  • In the technique of " Call By Value " the compiler passes the value of the argument. When a single value ( or a single variable ) is passed to function as an actual argument is copied into the formal argument ( i.e. onto the function ).
  • Now, the value of the corresponding formal argument can be altered within the function, but the value of actual argument within the calling portion will remain same . Thus the changes done in the function will not be reflected in calling portion.
  • This procedure of passing value of an argument to a function is known as call by value or pass by value. consider example of swapping of two numbers:
  • 
    #include<stdio.h>
    	void swap(int ,int);
    	void main(){
    	  int a=5,b=10;
    	  swap(a,b);
    	  printf("value main function after swapping in swap function \n a=%d and b=%d",a,b);
    	}
    	
    	void swap(int a,int b){
    	  int temp=a;
    	  a=b;
    	  b=temp;
    	  printf("value inside swap function after swapping \n a=%d and b=%d\n",a,b);
    	}
    
    

    Output:

    
    value inside swap function after swapping 
    a=10 and b=5
    value in main function after swapping in swap function
    a=5 and b=10
    
    

  • Print Page