Home

A program to explain functions using pointers

C Programming Language 106

Program

#include <stdio.h>

void swap(int *p, int *q)
{
    int t;
    t = *p;
    *p = *q;
    *q = t;
}
void main()
{
    int a = 10, b = 15;
    swap(&a, &b);
    printf("After swapping...\na = %d\nb = %d", a, b);

    printf("\n");
}

Result

After swapping...
a = 15
b = 10


Last Updated on

Next Post: Rules vs Guidelines →

Comments