Which of the following gives the memory address of a variable pointed to by pointer p_a?
A. p_a;
B. *p_a;
C. &p_a;
D. address( p_a );
So I'm reading this book called "Jumping into C++" and this quiz came up after one chapter. When I checked the right answer from the book it showed that the correct answer was C. &p_a;. Wouldn't &p_a just give the memory address of a pointer variable p_a instead of memory address of variable it is pointing to?
Now I'd say that this is not the correct answer, but I can't be sure. After all I'm still a beginner so I don't dare to start questioning answers in the book just yet. I'd say that the correct answer is A. Tell me, is there a mistake in the answers or what?
p_a
is a pointer pointing to a variable. That is, it yields the address of that variable.
*p_a
is the value of the variable.
&p_a
is the address of the pointer (pointers have memory locations too).
address( p_a )
is some nonsense.
Hence the answer is A and the book is incorrect. Burn it.
Unless I am totally misunderstanding the question, you are right and the book is wrong. p_a
is a pointer, meaning it is the address of the variable it points to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With