function call by reference c++ code example
Example 1: calling by reference c++
int main() {
int b = 1;
fun(&b);
return 0;
}
Example 2: calling by reference c++
void fun(int *a)
{
*a = 10;
}
Example 3: call by reference c++ example
#include <iostream>
using namespace std;
void swap(int& x, int& y) {
cout << x << " " << y << endl;
int temp = x;
x = y;
y = temp;
cout << x << " " << y << endl;
}
int main() {
int a = 7;
int b = 9;
swap(a, b);
}
Example 4: calling by reference c++
void fun2(int& a)
{
a = 5;
}
int main()
{
int b = 10;
fun2(b);
return 0;
}