View Single Post
Old Feb 4th, 2007, 6:41 PM   #1
Thiengineer
Newbie
 
Join Date: Feb 2007
Posts: 2
Rep Power: 0 Thiengineer is on a distinguished road
How do I swap pointers with a function?

I need help with the following problem about swapping pointers.

The following code is in main:
	main()
        {
           int x=1,y=2;
           int *xp,*yp;
           .
           .
           .
           xp = &x;
           yp = &y;
           intpswap(<arg1>,<arg2>);
           x=3;y=4;
           printf("*xp = %d, *yp = %d\n",*xp,*yp); 
        }
Write a function called intpswap that swaps what xp and yp point at,
and thus printf prints "*xp = 4, *yp =3".

I know how to swap int values by using a temp variable, but is it the same approach here?

Any help or hints will be greatly appreciated!!

Thank you!!

Last edited by Thiengineer; Feb 4th, 2007 at 7:09 PM.
Thiengineer is offline   Reply With Quote