C Program to reverse a number using call by reference


In this program, You will learn how to reverse a number using a call by reference in c.


Call by Reference

void reverse(int n, int *rev) { 
     //statement
}

Example: How to reverse a number using call by reference in c

#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("Reverse number is:%d", rev);

    return 0;
}

Output:

Enter a number:123
Reverse number is:321