bsc

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

root / semester_1 / practice-c / pc-ip-07.c

pc-ip-07.c (574B)


      1 /*
      2  * Question 7:
      3  * Write a program to swap two numbers using pointers using user-defined function.
      4  */
      5 
      6 #include <stdio.h>
      7 
      8 void swap(int *, int *);
      9 
     10 int main()
     11 {
     12     int a, b;
     13     printf("Enter two number: ");
     14     scanf("%d %d", &a, &b);
     15     printf("\nBefore Swap: ");
     16     printf("\nA = %d, Loc: %p", a, &a);
     17     printf("\nB = %d, Loc: %p", b, &b);
     18     swap(&a, &b);
     19     printf("\nAfter Swap: ");
     20     printf("\nA = %d, Loc: %p", a, &a);
     21     printf("\nB = %d, Loc: %p", b, &b);
     22     return 0;
     23 }
     24 
     25 void swap(int *a, int *b)
     26 {
     27     int temp = *a;
     28     *a = *b;
     29     *b = temp;
     30 }
© 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