assignment-s-09.c ​
Metadata ​
- Author — Amit Dutta (amitdutta4255@gmail.com)
- Last updated — 17 Dec 2025
- License — MIT
Problem Statement ​
Problem Statement
Write a program to swap two numbers using pointers (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 value for a and b: ");
scanf("%d %d", &a, &b);
printf("\nBefore Swap: ");
printf("\na = %d,\tAddress: %u", a, &a);
printf("\nb = %d,\tAddress: %u", b, &b);
swap(&a, &b);
printf("\nAfter Swap: ");
printf("\na = %d,\tAddress: %u", a, &a);
printf("\nb = %d,\tAddress: %u", b, &b);
return 0;
}
void swap(int *a, int *b)
{
*a = *a ^ *b;
*b = *a ^ *b;
*a = *a ^ *b;
}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