pc-ip-07.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 05 Jan 2026
- License — MIT
Problem Statement ​
Problem Statement
Question 7: Write a program to swap two numbers using pointers using user-defined function.
Source Code ​
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include <stdio.h>
void swap(int *, int *);
int main()
{
int a, b;
printf("Enter two number: ");
scanf("%d %d", &a, &b);
printf("\nBefore Swap: ");
printf("\nA = %d, Loc: %p", a, &a);
printf("\nB = %d, Loc: %p", b, &b);
swap(&a, &b);
printf("\nAfter Swap: ");
printf("\nA = %d, Loc: %p", a, &a);
printf("\nB = %d, Loc: %p", b, &b);
return 0;
}
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25