The variables xp and yp have both been declared as pointers to integers, and have been assigned values. write the code to exchange the two integers (so that after the swap xp still points at the same location, but it now contains the integer value originally contained in the location pointed to by y; and vice versa-- in other words, in this exercise you are swapping the integers, not the pointers). declare any necessary variables.

Respuesta :

tonb
You need one temp variable to hold one of the values while you move the other. The asterisk in front of the variable will dereference it, ie., you'll be accessing the value pointed to the pointer rather than the pointer itself.

int temp;

temp = *xp;
*xp = *yp;
*yp = temp;