Call-by-value-function in C++ .

In this session i have discussed call by value function in C++ .


In call by value , the original value can not be changed or modified because when you passed the value to the function parameter it is locally stored in function parameter memeory address . So it can not change the varible value inside the caller function in main() because the variable inside the main() is stored at different memory location .


Example : Write a program that demonstrate the call by value function .

    #include<iostream>
    using namespace std; 
    void display(int x);
    int main()
    {  
          int x;
          x=10;
          cout<<" Value display from function\n ";
          display(x);
          cout<<"\nValue display from x variable\n";
          cout<<"x : "<<x;
          return 0;
    }
    void display(int x)
    {
        x=x+10;
        cout<<"x : "<<x;
    }
    
    OUTPUT : Value display from function
             x : 20
             Value display from x variable
             x : 10
    


Welcome to AndroidATPoint.

back image                     next image