What is the meaning of the address of a pointer?

前端 未结 4 2125
我寻月下人不归
我寻月下人不归 2021-01-06 13:14

If we have code:

int b = 10;
int* a = &b;
std::cout << a << \" \" << &a << \" \";

As the result, the addres

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-06 13:41

    A pointer has the value of a variable's address

    I assume by a variable you mean the object corresponding to the variable. Nonetheless, this is not strictly true, and it's the edgecases where we start to make distinctions between addresses and pointer values.

    There are pointer values that don't point at objects at all. Consider null pointers, for example.

    Addresses, by definition, do point at objects... or functions.

    what's the meaning of address of a pointer?

    The term address of a pointer makes sense if you can imagine a variable declared to store a pointer (e.g. T *var;) and you take the address of it (&var).

    so why we have the address of an address?

    An address is a type of pointer value, but pointer values don't point at values; they point at objects or functions. &a is different to a because the two pointers point at different objects; one points at a and the other points at b.

提交回复
热议问题