C++ Program to check number is palindrome or not using call by Reference


In this program, You will learn how to check number is palindrome or not using call by Reference in C++.


Call by Reference

void check(int n, int *p){ }


Example: How to check number is palindrome or not using call by Reference in C++

Run it Now
#include<iostream>
using namespace std;

void check(int n, int *p) {

    int r, rev = 0;
    while (n > 0) {
        r = n % 10;
        rev = rev * 10 + r;
        n = n / 10;
    }
    *p = rev;
}

int main() {

    int n, p = 0;

    cout << "Enter a Number :";
    cin>>n;

    check(n, &p);
    if (p == n) {
        cout << "\nThe Number is Palindrome :" << n;
    } else {
        cout << "\nThe Number is Not Palindrome :" << n;
    }

    return 0;
}

Output:

Enter a Number :121
The Number is Palindrome :121