C++ Program to reverse a number using call by Reference
In this program, You will learn how to reverse a number using call by Reference in C++.
Call by Reference
void reverse(int n, int *rev) {
//statement
}
Example: How to reverse a number using call by Reference in C++.
#include<iostream>
using namespace std;
void reverse(int n, int *rev) {
int r, re=0;
while (n > 0) {
r = n % 10;
re = re * 10 + r;
n = n / 10;
}
*rev = re;
}
int main() {
int n, rev = 0;
cout << "Enter a number:";
cin >> n;
reverse(n, &rev);
cout << "Reverse number is:" << rev;
return 0;
}
Output:
Enter a number:123
Reverse number is:321