Home

A program to explain CALL BY REFERENCE (address)

C Programming Language 083

Program

#include <stdio.h>

void swap(int *, int *);
void main()
{
    int a = 10, b = 20;

    printf("Before swapping...\n");
    printf("a = %d\n", a);
    printf("b = %d\n", b);
    printf("\n");

    swap(&a, &b);
    printf("After swapping...\n");
    printf("a = %d\n", a);
    printf("b = %d\n", b);

    printf("\n");
}

void swap(int *x, int *y)
{
    int t;
    t = *x;
    *x = *y;
    *y = t;
}

Result

Before swapping...
a = 10
b = 20

After swapping...
a = 20
b = 10


Last Updated on

Next Post: Rules vs Guidelines →

Comments