What is the meaning of the address of a pointer?

前端 未结 4 2158
我寻月下人不归
我寻月下人不归 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:30

    std::cout << a << " " << &a<<" ";
    

    Yes ,both are different .

    1. a has been assigned address of b , so it prints address of b.

    2. &a prints address of pointer a itself .

    And a and b don't have same address.

    It's similar(to understand) to this example -

    int b=9;
    

    If you print b you get its value i.e 9 but if you print &b you gets its address , and in no ways they will be same .

    Same is the case with pointers.

    A pointer has the value of a variable's address, since we have a variable in memory. But we don't have the value of address stored in memory, so why we have the address of an address?

    We declare a variable (pointers , array , just int, char) these all are declared in program and are stored in memory . As these are stored in memory ,they have their unique address.

提交回复
热议问题