Question

Suppose the following declarations and statement a


0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
Suppose the following declarations and statement are m effect What are the values of and b...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT