一道指针面试题

int a=(int)(((int *)0x0)+4);

这题其实很简单,但是我想错了。

这样拆分吧

首先这道题是计算什么,是计算地址。

char *p = NULL;

cout<<(int)p<<endl;

上面的结果就是打印为0。指针p里面记录着指向的地址,值为0。

如下,就是计算p1的地址

int * p = 0;

int *p1 = p+4;

cout<<(int)p1<<endl;

所以,p+4是偏移了4个字节。所以答案为16。

posted on 2013-06-18 09:50  51Liuda  阅读(128)  评论(0编辑  收藏  举报

导航