Actually when we initialize pointer like:
char *p;
We have *p
means value at p
(p
's address) and p
simply means address of p
. So when I want to print means:
cout << p
Why does not compiler give me p
's address?
Actually when we initialize pointer like:
char *p;
We have *p
means value at p
(p
's address) and p
simply means address of p
. So when I want to print means:
cout << p
Why does not compiler give me p
's address?
Uninitialized pointers will point to either nowhere or some random address. This is implementation/compiler specific.
In your case, it must be getting initialized to 0 i.e null pointer or pointer pointing to nothing. And thus attempt to print its value results in this output. Some intelligent compilers do print (nil) in such cases.
You can confirm it by changing:
char *p;
to
char *p = 0;
You must get the same output i.e nothing will be printed.
On contrary to this, if initialized/assigned properly as below, you will get the address (but that will be the address p is pointing to, for printing address of p, you should print &p):
char *p, c='x';
p=&c;
Here is good read about related stuff.