programplug Logo




C++ Call By Value


original value is not modified

It is the default way of calling a function in C++ programming.In this method copies the actual value of an argument into the formal parameter of the function.
Means function creates a new set of variables and copies the values of the arguments into them.


#include 
int sum(int a, int b)
{
     int c=a+b;
     return c;
}

int main(
{
    int v1 = 20;
    int v2 = 20;
    int v3 = sum(v1,v2);
	cout<<"Sum Is \n"<< v3 ; 
    return 0;
}

In above a and b are the formal parameters.
Variable v1 and v2 are the actual arguments(parameters).


Example : Swapping numbers using Function Call by Value


#include 
void swap( int a, int b )
{
   int temp;
   temp = a;
   a = b;
   b = temp;
}
int main()
{
    int n1 = 10, n2 = 20 ;
    cout<<"Before swapping"<< n1 << n2;
    swap(n1, n2);
    cout<<"After swapping"<< n1 << n2;
}

Output:
Before swapping: 10, 20
After swapping: 10, 20






Our Services

Developing Cheapest Websites
Offer Digital Marketing
Provide College Projects
Attractive Website Developing
Summer Training,Industrial Training
SCO,SMO

Contact Us

Dehradun Uttarakhand India
www.programplug.com
info@programplug.com
08534019974
Designed By : Mridul Gupta

Other Link

About Us

Contact Us

Disclaimer

Privacy Policy