If I have a pointer like:
int* ptr;
and I do:
printf("%#x\n%#x\n%#x\n", ptr, ptr+1, ptr+2);
I get the output as:
some address
some address + 4bytes
some address + 8bytes
Now if I make the pointer short int* ptr
I print in the same way as above and get the output as:
some address
some address + 2bytes
some address + 4bytes
Why is that? Aren't addresses unsigned integers? If so, then the datatype to which a pointer is pointing to should not matter. The pointer will always store an address which is an unsigned int hence it would occupy 4 bytes. Why is a short int pointer occupying 2bytes whereas an int pointer is occupying 4bytes? In the end, both pointers store addresses only, isn't it?