The correct answer for "Jumping in C ++", chapter 13, poll 3?

Which of the following values ​​gives the memory address of the variable pointed to by p_a?

a. P_A;

B. * P_A;

C. & amp; P_A;

D. address (p_a);

So, I am reading this book entitled "Jumping in C ++", and this poll appeared after one chapter. When I checked the correct answer from the book, he showed that the correct answer was C. & amp; P_A; . Wouldn't p_a just want to specify the memory address of the pointer variable p_a instead of the memory address of the variable that it points to?

Now I would say that this is not the right answer, but I can not be sure. In the end, I'm still a newbie, so I dare not start interrogating the answers in the book. I would say the correct answer: A. Tell me, is there an error in the answers or what?

+4
source share
4 answers

p_a- A pointer to a variable. That is, it gives the address of this variable.

*p_a is the value of the variable.

&p_a - This is the address of the pointer (pointers also have memory locations).

address( p_a ) - This is some kind of stupidity.

Therefore, the answer is A , and the book is incorrect. Write it down .

+4
source

If I do not completely understand the question, you are right, and the book is wrong. p_a- a pointer, that is, the address of the variable that it points to.

+4

, : A.

  • p_a - , ,
  • *p_a , ,
  • &p_a ,
  • address(p_a) address, - , .

( std::addressof(p_a), p_a, &p_a, , &. . )

+1

. , . , , A., p_a.

0
source

Source: https://habr.com/ru/post/1525263/


All Articles