Question: As an application of the property that a a = 0 for any bit vector a, consider the following program: As the name implies,

As an application of the property that a " a = 0 for any bit vector a, consider the following program:

1 2 3 4 5 void inplace_swap (int *x, int *y) { *y = *x /* Step 1 */ /* Step 2 */ /* Step 3 */ } *y = *x ~ *y;

As the name implies, we claim that the effect of this procedure is to swap the values stored at the locations denoted by pointer variables x and y. Note that unlike the usual technique for swapping two values, we do not need a third location to temporarily store one value while we are moving the other. There is no performance advantage to this way of swapping; it is merely an intellectual amusement. Starting with values a and b in the locations pointed to by x and y, respectively, fill in the table that follows, giving the values stored at the two locations after each step of the procedure. Use the properties of ᵔ to show that the desired effect is achieved. Recall that every element is its own additive inverse (that is, a ᵔ a = 0).

Step Initially Step 1 Step 2 Step 3 *X a *y b

1 2 3 4 5 void inplace_swap (int *x, int *y) { *y = *x /* Step 1 */ /* Step 2 */ /* Step 3 */ } *y = *x ~ *y; *y; *y;

Step by Step Solution

3.46 Rating (156 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This procedure relies on the fact tha... View full answer

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 Computer Systems A Programmers Perspective Questions!