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).
#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