" Consider below fragment of code. Assume the integers occupy 4 bytes and that m is stored in memory starting at byte 0x3fffd00.

int m = 44;
int *p = &m;
int &r = m;
int n = (*p) ++;
int *q = p-1;
r = *(--p) + 1;

what is the value ?

Could you mind do it step by step?
I did not know how to do it!

Hello Daniel, thank you for the question.

Don't you just hate these tricky pointer questions? Always very meticulous and intricate. I drew this one out on a piece of paper to make sure I got it right. I'll try to break this down into individual steps to make it simpler. I'm going to number this list so to make it easier to understand. If 2 things happen on the same line, then the operation affected both of them:

1. m = 44
2. *p = 44
3. r = 44
4. n = 44, p = 45 because of postfix ++, r = 45, m = 45
5. q = 0x3fffc15(if my hex math isn't too rusty), value undefined
6. r = undefined number + 1, m = undefined number + 1, p = 0x3fffc14
7. q = undefined number + 1

I haven't had to convert hex in a while, but I believe I got it right. Also, you can copy and paste that code into the int main() of your favorite compiler and check all the data with the debugger if you wish. Though that won't justify the memory address issue.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2017 About.com. All rights reserved.