assignment-s-09.c (585B)
1 /* Write a program to swap two numbers using pointers (user-defined function). */ 2 3 #include <stdio.h> 4 5 void swap(int *, int *); 6 7 int main() 8 { 9 int a, b; 10 printf("Enter value for a and b: "); 11 scanf("%d %d", &a, &b); 12 printf("\nBefore Swap: "); 13 printf("\na = %d,\tAddress: %u", a, &a); 14 printf("\nb = %d,\tAddress: %u", b, &b); 15 swap(&a, &b); 16 printf("\nAfter Swap: "); 17 printf("\na = %d,\tAddress: %u", a, &a); 18 printf("\nb = %d,\tAddress: %u", b, &b); 19 return 0; 20 } 21 22 void swap(int *a, int *b) 23 { 24 *a = *a ^ *b; 25 *b = *a ^ *b; 26 *a = *a ^ *b; 27 }