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


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


Call by Reference

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


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

Run it Now
#include<stdio.h>

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;

    printf("Enter a number : ");
    scanf("%d", &n);

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

    return 0;
}

Output:

Enter a number : 121
The Number is Palindrome : 121