The following code shows an Example of Call By Value and Call By Reference in C.

While, call by value in a function refers to calling a function where function parameters are passed by value. In other words, within the function only a copy of the actual parameters is maintained which is separately updated. Hence, the value of actual parameters remain unchanged. For instance, in the function f2(), the value of x and y is copied in separate location and is changed there only. So, the changes are not reflected in actual parameters.

In contrast, when the function is called by reference, the address of function parameters is passed instead of there values. Therefore, all updates within the function are done at actual locations. Hence, when the function returns, updates are reflected in actual parameters. For instance, the function f2() uses call by reference, Therefore, we get the updated values.

// Call By Value and Call By Reference

#include <stdio.h>
void f1(int *a, int *b)
{
    *a=*a**b;
    *b=*a+*b;
}
void f2(int a, int b)
{
    a=a*b;
    b=a+b;
}
int main()
{
    int x, y;
    x=8;
    y=12;
    printf("Before function call, x=%d, y=%d", x, y);
    printf("\nCall By Value....");
    f2(x, y);
    printf("\nAfter function call, x=%d, y=%d", x, y);
    x=8;
    y=12;
    printf("\nBefore function call, x=%d, y=%d", x, y);
    printf("\nCall By Reference....");
    f1(&x, &y);
    printf("\nAfter function call, x=%d, y=%d", x, y);    
    return 0;
}

Output

Calling Functions Using Call By Value and Call By Reference
Calling Functions Using Call By Value and Call By Reference

Further Reading

50+ C Programming Interview Questions and Answers

C Program to Find Factorial of a Number