Suppose the following declarations and statement are m effec
Solution
Note: x = &a means x is an integer pointer which should store the address of the variable a. & is the addressOf operator. By *x, we denote the value of the variable stored at the address x. * is the valueAt operator.
Answers
(a) a = 20, b = 20.
This is because, x and y are the pointers which point to the memory locations where a and b are stored, respectively.
When you set *x = *y, it means you are assigning the variable stored in the address denoted by x (which is a) to the value of the integer stored in the address denoted by the pointer y(which is b).
Hence, both a and b would have value 20, in the end.
(b) a = 2, b = 5.
This is because, x and y are the pointers which point to the memory locations where a and b are stored, respectively.
When you set *x = *y, it means you are assigning the variable stored in the address denoted by x (which is a) to the value of the integer stored in the address denoted by the pointer y(which is b). At this point, a = 20, b = 20.
After this, you have *x = 2, i.e. you are assigning the variable stored in the address denoted by the pointer x (which is a) to 2.
Then, *y = 5, i.e. you are assigning the variable stored in the address denoted by the pointer y (which is b) to 5.
(c) a = 22, b = 19.
This is because, x and y are the pointers which point to the memory locations where a and b are stored, respectively.
When you set *x = *y, it means you are assigning the variable stored in the address denoted by x (which is a) to the value of the integer stored in the address denoted by the pointer y(which is b). At this point, a = 20, b = 20.
After this, you have *x += 2, i.e. you instruct to increase the value of the variable stored in the the address denoted by x (which is a) by 2.
Finally, you have (*y)--, i.e. you instruct to decrease the value of the variable stored in the the address denoted by y (which is b) by 1.
