[email protected]:~$ cat /tmp/test.c
#include<stdio.h>
int main(void)
{
int m=1;
printf("m=%d\n",&m);
printf("m=%p\n",&m);
}
[email protected]:~$ gcc /tmp/test.c -o /tmp/test.exe
[email protected]:~$ /tmp/test.exe
m=-1078061268
m=0xbfbe172c
[email protected]:~$ python
Python 2.7.3 (default, Jan 2 2013, 16:53:07)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print hex(-1078061268)
-0x4041e8d4
为什么-1078061268
在dec中不等于0xbfbe172c
in hex?为什么地址编号在十进制和十六进制中不相等?
这些数字是相等的。由于sign属性和不同的基数(16 vs 10),十六进制值看起来与unsigned int不同。 – tay10r
除了识别十进制与十六进制模式的问题之外,还存在更严重的问题。永远不要使用'%d'打印指针。整数和指针通常具有不同的宽度,所以'printf'会严重混淆它的参数,导致程序崩溃。 –