Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- swap_integers_by_pointers_v1.c
- Task from Mirha Wali
- https://web.facebook.com/mirha.wali.3154
- https://web.facebook.com/photo.php?fbid=144111560601973&set=gm.1591028384389339&type=3&theater
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- // function to swap the integers a and b
- void swap( int *a, int *b )
- {
- int temp;
- printf("\n In function swap(), before swapping: \n");
- printf("\n Value a = %d is on address %p \n", *a, a );
- printf("\n Value b = %d is on address %p \n\n", *b, b );
- temp = *a;
- *a = *b;
- *b = temp;
- printf("\n In function swap(), after swapping: \n");
- printf("\n Value a = %d is on address %p \n", *a, a );
- printf("\n Value b = %d is on address %p \n", *b, b );
- }
- int main(void)
- {
- int a=2, b=3;
- swap( &a, &b );
- printf("\n\n In main(), after calling function swap() \n");
- printf("\n Value a = %d is on address %p \n", a, &a );
- printf("\n Value b = %d is on address %p \n", b, &b );
- return 0;
- } // main()
Add Comment
Please, Sign In to add comment