All articles
c

A program to explain functions using pointers

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 106

  • Write a program to explain functions using pointers

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

Comments