dmilicev

swap_integers_by_pointers_v1.c

May 27th, 2020 (edited)
163
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3.     swap_integers_by_pointers_v1.c
  4.  
  5.     Task from Mirha Wali
  6.     https://web.facebook.com/mirha.wali.3154
  7.  
  8.     https://web.facebook.com/photo.php?fbid=144111560601973&set=gm.1591028384389339&type=3&theater
  9.  
  10.  
  11.     You can find all my C programs at Dragan Milicev's pastebin:
  12.  
  13.     https://pastebin.com/u/dmilicev
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18.  
  19. // function to swap the integers a and b
  20. void swap( int *a, int *b )
  21. {
  22.     int temp;
  23.  
  24.     printf("\n In function swap(), before swapping: \n");
  25.     printf("\n Value a = %d is on address %p \n", *a, a );
  26.     printf("\n Value b = %d is on address %p \n\n", *b, b );
  27.  
  28.     temp = *a;
  29.     *a = *b;
  30.     *b = temp;
  31.  
  32.     printf("\n In function swap(), after swapping: \n");
  33.     printf("\n Value a = %d is on address %p \n", *a, a );
  34.     printf("\n Value b = %d is on address %p \n", *b, b );
  35. }
  36.  
  37. int main(void)
  38. {
  39.     int a=2, b=3;
  40.  
  41.     swap( &a, &b );
  42.  
  43.     printf("\n\n In main(), after calling function swap() \n");
  44.     printf("\n Value a = %d is on address %p \n", a, &a );
  45.     printf("\n Value b = %d is on address %p \n", b, &b );
  46.  
  47.     return 0;
  48.  
  49. } // main()
  50.  
RAW Paste Data Copied