call by value, Function in C++, working of call by value
Simple example of Function in C++, which explain the working of call by value:

Program Code:
#include <iostream>
using namespace std;
void swap(int x, int y);
int main () 
{
int a = 100;
int b = 200;
cout << "Before swap, value of a :" << a << endl;
cout << "Before swap, value of b :" << b << endl;
swap(a, b);
cout << "After swap, value of a :" << a << endl;
cout << "After swap, value of b :" << b << endl;
return 0;
}
void swap(int x, int y) 
{
int temp;
temp = x; 
x = y;    
y = temp; 
return;
}


The output of the program is tested on www.jdoodle.com

Output:
Before swap, value of a :100
Before swap, value of b :200
After swap, value of a :100
After swap, value of b :200


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: