C++ Program to check number is a palindrome or not using pointers


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


Some list is : 11 22 121 131

Example: How to check number is a palindrome or not using pointers in C++.

#include<iostream>
using namespace std;

int main() {

    int n, num1, r, rev = 0;
    int *num;

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

    num1 = n;
    num = &n;

    while (*num > 0) {
        r = *num % 10;
        rev = rev * 10 + r;
        *num = *num / 10;
    }

    if (rev == num1) {
        cout << "Number is palindrome:" << num1;
    } else {
        cout << "Number is not palindrome:" << num1;
    }

    return 0;
}

Output:

Enter a number:121
Number is palindrome:121