What is call by reference in C language?

Pass by reference means addresses are sent as arguments.

The call by reference or pass by reference method passes the arguments to a function by the means of address to an argument. This is done into the formal parameter. Inside the function, the address is used to access an actual argument.


void main(){
   void swap(int *,int *);
   int a,b;
   printf("enter 2 numbers");
   printf("Before swapping a=%d b=%d",a,b);
   swap(&a, &b); //address are sent as an argument
   printf("after swapping a=%d, b=%d",a,b);
void swap(int *a,int *b){
   int t;
   *a=*b; // *a = (*a + *b) – (*b = * a);


When the above program is executed, it produces the following result −

enter 2 numbers 10 20
Before swapping a=10 b=20
After swapping a=20 b=10