If we have code:
int b = 10;
int* a = &b;
std::cout << a << \" \" << &a << \" \";
As the result, the addres
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.