1void fun2(int& a)
2{
3 a = 5;
4}
5
6int main()
7{
8 int b = 10;
9 fun2(b);
10
11 // now b = 5;
12 return 0;
13}
1//call by reference example c++
2#include <iostream>
3
4using namespace std;
5
6void swap(int& x, int& y) {
7 cout << x << " " << y << endl;
8 int temp = x;
9 x = y;
10 y = temp;
11 cout << x << " " << y << endl;
12
13}
14
15int main() {
16
17 int a = 7;
18 int b = 9;
19
20 swap(a, b);
21
22}
23
1void fun3(int a)
2{
3 a = 10;
4}
5
6int main()
7{
8 int b = 1;
9 fun3(b);
10 // b is still 1 now!
11 return 0;
12}