int firstInt =10;
int *pointerFirstInt = &firstInt;
printf("The address of firstInt is: %u", &firstInt);
printf("\n");
printf("The address of firstInt is: %p", pointerFirstInt);
printf("\n");上面的代码返回以下内容:
The address of firstInt is: 1606416332
The address of firstInt is: 0x7fff5fbff7cc我知道0x7fff5fbff7cc是十六进制的,但是当我试图将这个数字转换为十进制时,它并不等于1606416332。为什么会这样呢?两个不应该都返回相同的内存地址吗?
发布于 2014-09-12 09:07:59
从你的十六进制地址-
The address of firstInt is: 0x7fff5fbff7cc地址的大小是6个字节长。但是unsignedint的大小是4个字节。当您试图使用%u打印地址时,它将导致未定义的行为。
因此,始终使用%p打印地址。
https://stackoverflow.com/questions/25804498
复制相似问题