bsc

Comprehensive codebase and cou...
Log | Files | Refs | Activity | README | LICENSE

root / semester_1 / internal-practice / IP-07.c

IP-07.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 }
© notamitgamer • Site Built: 2026-09-05 01:53:16 UTC • git-mirror commit: c170d72 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror