Question: 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

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 yp; and vice versa-- in other words, in this exercise you are swapping the integers, not the pointers). Declare any necessary variables.

This is what I tried:

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!