0
Size of pointer
I have following code int *p,a; a=10; p=&a; printf ("size of p %d\n",sizeof (p)); printf ("size of p %d\n",sizeof (*p)); output: 8 4 so what size of pointer p should I consider 8 or 4 and also please answer why ?
8 ответов
+ 1
Int is treated as 64 bit number, so 8 bytes. Pointer to int is 4 bytes.
0
But if p is treated as int then why it's size is not 8 byte
0
and what size should I consider when someone is referring to address of pointer
0
p is a pointer to an int, not an int. Think of it this way: you need less space to store an url than the content of the page. But some machines will have 64 bit pointers
0
I got it
as I'm compiling on 64 bit machine
address is going to b 64 bit so sizeof (p)
is address where as sizeof (*p) is size of intiger a
0
But I think sololearn uses a 64 bit compiler, so i think the pointer should also be 64 bits, but thats not the case.
0
If its 64 bit then memory addresses associated with variables will also be 64 bit then 8 output is correct
and pointers always have size equal to intiger type anyhow.
0
then your question is not answered.