Character pointer and size

Hello Everyone,
In have a doubt in pointer size.

char *p;
cout<<sizeof(p);
cout<<sizeof(*p);

first will print 2
second will print 1

why it so?

Thanks in advance
Sasikuamr
Better question, why do you think it should be different?
sizeof char is 1 by definition (sizeof returns the size of a type in multiples of char).
You're apparently compiling for a 16 bit system, so your pointer size is 2 bytes (assuming char is 8 bit wide).
I think it's important to remember notation here. (*p) is "the variable pointed to by p" & as Athar said is of datatype char which has a size of 1. p is simply a pointer which has size 2. Athar said it all, just using different language so it maybe makes sense at least one of the two ways.
I'm surprised the pointer wasn't 4 bytes myself but since the pointer is simply an address, the size of the integer variable that holds the address could vary depending on the system.
Topic archived. No new replies allowed.