I am studying pointers and found I get incorrect size of a pointer.
What I learned is that since p_num
is a pointer to an int, it should show 4 bytes but is shows 8.
What could the possible reason for it?
#include <stdio.h>
int main()
{
int num = 0;
int * p_num = NULL;
num = 10;
printf("num address: %p\n", &num);
printf("num size: %zd\n", sizeof(num));
printf("num value: %d\n\n", num);
p_num = #
printf("p_num address: %p\n", (void*)&p_num);
printf("p_num size: %zd\n", sizeof(p_num));
printf("p_num value: %p\n", p_num);
printf("p_num value pointed: %d\n", *p_num);
return 0;
}
Output:
num address: 0x7fffcb0e8ffc
num size: 4
num value: 10
p_num address: 0x7fffcb0e8ff0
p_num size: 8
p_num value: 0x7fffcb0e8ffc
p_num value pointed: 10