M
M
Maxim Rudnev2016-01-12 21:53:45
Programming
Maxim Rudnev, 2016-01-12 21:53:45

pointer addresses?

cout <<"значение= "<< *b <<"\tадрес= 0х"<<b<<"  =0x"<< &b<< endl;

Help to understand with display of the address of the pointer. When compiling the line, the following result comes out
3cbec5ac478e4119b924ac3f0229c273.png
. Last addresses who is responsible for what? Why are they different?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2016-01-12
@stigmt

Because pointers are, first of all, the same variables as any others (this is very important to understand). The second output value is the value of b, and it doesn't really matter if it's a pointer or not (in our case, yes, a pointer, and so the output value of b is some address). The third value printed is the ADDRESS of b, and it doesn't matter what type b is. You can declare int b or float b and get the same result.
That's what is the distinguishing point of the pointer - it's just the same first displayed value, or rather, the very possibility of deriving it. For pointers (as well as for any user-defined types that implement operator*), a dereference operation is available. This makes it possible to take the value of the variable b, interpret it as an address, and then, in turn, get into memory at this address and get the value from there. In this case, it can be argued that the value 66 is located at address 0x011CD1C0 (if it is interpreted according to the type of pointer).

E
evnuh, 2016-01-12
@evnuh

because the first address is the address of the memory cell where the value 66 is stored the
second address is the address of the memory cell where the address of another memory cell is stored where the value 66 is stored

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question