C++ Programming Code Examples C++ > Mathematics Code Examples Program to Swap Numbers in Cyclic Order Using Call by Reference Program to Swap Numbers in Cyclic Order Using Call by Reference This program takes three integers from the user and swaps them in cyclic order using pointers. Three variables entered by the user are stored in variables a, b and c respectively. Then, these variables are passed to the function cyclicSwap(). Instead of passing the actual variables, addresses of these variables are passed. When these variables are swapped in cyclic order in the cyclicSwap() function, variables a, b and c in the main function are also automatically swapped. Notice that we haven't returned any values from the cyclicSwap() function. #include<iostream> using namespace std; void cyclicSwap(int *a, int *b, int *c); int main() { int a, b, c; cout << "Enter value of a, b and c respectively: "; cin >> a >> b >> c; cout << "Value before swapping: " << endl; cout << "a, b and c respectively are: " << a << ", " << b << ", " << c << endl; cyclicSwap(&a, &b, &c); cout << "Value after swapping numbers in cycle: " << endl; cout << "a, b and c respectively are: " << a << ", " << b << ", " << c << endl; return 0; } void cyclicSwap(int *a, int *b, int *c) { int temp; temp = *b; *b = *a; *a = *c; *c = temp; }