C Program to find factorial of a number using call by Reference


In this program, You will learn how to find factorial of a number using call by Reference in C.


Call by Reference

void fact(int n,int *f){ }


Example: How to find factorial of a number using call by Reference in C

Run it Now
#include<stdio.h>

void fact(int n, int *f) {
    int i;
    for (i = 1; i <= n; i++) {
        *f = *(f) * i;
    }
}

int main() {

    int n, f = 1;
    printf("Enter a number : ");
    scanf("%d", &n);

    fact(n, &f);
    printf("\nFactorial is : %d", f);

    return 0;
}

Output:

Enter a number : 4
Factorial is : 24