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<stdio.h>

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;

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

    reverse(n, &rev);
    printf("\nThe reverse number is : %d", rev);

    return 0;
}

Output:

Enter a number : 123
The reverse number is : 321