Question: The following problem illustrates the way memory aliasing can cause unexpected program behavior. Consider the following procedure to swap two values: 1 2 3 4

The following problem illustrates the way memory aliasing can cause unexpected program behavior. Consider the following procedure to swap two values:

1 2 3 4 5 67 /* Swap value x at xp with value y at yp */ void swap(long *xp, long *yp) { *xp = *xp + *yp; /*

1 2 3 4 5 67 /* Swap value x at xp with value y at yp */ void swap (long *xp, long *yp) { *xp = *xp + *yp; /* x+y *yp *xp *xp = *xp = - */ *yp: /* x+y-y = x */ *yp; /* x+y-x = y */ } If this procedure is called with xp equal to yp, what effect will it have?

Step by Step Solution

3.36 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This problem illustrates some of the subtle effects of memory aliasing As the following commented ... 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!