assignment-s-09.c
Problem Statement
assignment-s-09.c
Write a program to swap two numbers using pointers (user-defined function).
Source Code
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
● Author - Amit Dutta · Updated - 17 Dec 2025