The variables xp and yp have both been declared as pointers

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 .

Solution

// declare variable t
int t = 0;
// pointer pointing to the address of t
int *temporary = &t;

// swap the integers
temporary = xp;
xp = yp;
yp = temporary

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 a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site