I am practicing on C programming language. I had Win 10 systems and I was practicing on it and I always get addresses which are multiples of 2. Know, I am practicing on Macbook Pro M3 and I get 9 digit addresses. So, nine is odd.
Also, here is the code and result:
#include <stdio.h>
int main(void)
{
int m = 10, n, o, *z;
z = &m;
printf("z stores the address of m = %p\n", z);
printf("*z stores the value of m = %d\n", *z);
printf("&m is the address of m = %p\n", &m);
printf("&n stores the address of n = %p\n", &n);
printf("&o stores the address of o = %p\n", &o);
printf("&z stores the address of z = %p\n", &z);
return 0;
}
z stores the address of m = 0x16fa13228
*z stores the value of m = 10
&m is the address of m = 0x16fa13228
&n stores the address of n = 0x16fa13224
&o stores the address of o = 0x16fa13220
&z stores the address of z = 0x16fa13218
I researched about it however I couldn't get good answers. Here what I found:
why the value of address in c s always even?
Strange address of a C variable in Mac OS X
I was expecting to see addresses in even digits.
From the C23 draft:
7.23.6.1 The
fprintffunctionThat means that different implementations may produce different output, even if the actual pointer values would happen to be the same.
I'm assuming this means that you expected to see an even number of digits. Typically, no more than the significant non-zero digits will be printed so if you get 9 digits on your Mac, that's just an effect of that. A 32 bit address like
0x00000FFFwill often be printed as just0xFFF.If you want the same format on all platforms and implementations, you could cast the pointer to
uintptr_tand print that instead.Example:
Possible output: