arox14

Swap 2 Num w/ Pointers

Nov 28th, 2021
715
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2.  
  3. int main()
  4. {
  5.     int num1, num2, *pnum1= &num1, *pnum2= &num2;
  6.     printf("Enter num 1\n");
  7.     scanf("%d", &num1);
  8.     printf("Enter num 2\n");
  9.     scanf("%d", &num2);
  10.     printf("Before Swap: %d \t %d\n", *pnum1,*pnum2);
  11.     *pnum1 = *pnum1 + *pnum2;
  12.     *pnum2 = *pnum1 - *pnum2;
  13.     *pnum1 = *pnum1 - *pnum2;
  14.     printf("After Swap:  %d \t %d\n", *pnum1,*pnum2);
  15. }
RAW Paste Data