I started reading Pointers and while tinkering with them. I stumbled upon this :
#include
int main()
{
int *p,a;
a=sizeof(*p);
pri
Every beginner always gets confused with pointer declaration versus de-referencing the pointer, because the syntax looks the same.
int *p;
means "declare a pointer to int". You can also write it as int* p;
(identical meaning, personal preference).*p
, when used anywhere else but in the declaration, means "take the contents of what p points at".Thus sizeof(*p)
means "give me the size of the contents that p points at", but sizeof(int*)
means "give me the size of the pointer type itself". On your machine, int
is apparently 4 bytes but pointers are 8 bytes (typical 64 bit machine).
*p
and int*
are not the same things! First one is a dereferenced pointer (i.e. int
which is 4 bytes wide) and the second one is a pointer (8 bytes wide in your case since it's a 64 bit machine).