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){ }


Example: How to reverse a number using call by Reference in C++

Run it Now
#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 << "\nThe Reverse Number is:" << rev;

    return 0;
}

Output:

Enter a Number :1023
The Reverse Number is:3201