bsc

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

assignment-s-10.c (721B)


      1 /*
      2  * Author: Amit Dutta (amitdutta4255@gmail.com) | Date: 17 Dec 2025
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* Write a program to swap two numbers using pointers (user-defined function). */
      8 
      9 #include <stdio.h>
     10 
     11 void swap(int *, int *);
     12 
     13 int main()
     14 {
     15     int a, b;
     16     printf("Enter value for a and b: ");
     17     scanf("%d %d", &a, &b);
     18     printf("\nBefore Swap: ");
     19     printf("\na = %d,\tAddress: %u", a, &a);
     20     printf("\nb = %d,\tAddress: %u", b, &b);
     21     swap(&a, &b);
     22     printf("\nAfter Swap: ");
     23     printf("\na = %d,\tAddress: %u", a, &a);
     24     printf("\nb = %d,\tAddress: %u", b, &b);
     25     return 0;
     26 }
     27 
     28 void swap(int *a, int *b)
     29 {
     30     *a = *a ^ *b;
     31     *b = *a ^ *b;
     32     *a = *a ^ *b;
     33 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror