//假设p的值是0x100000.已知结构体Test类型的变量大小是20个字节
struct Test
{
int Num;
char *pcName;
short sDate;
char cha[2];
short sBa[4];
}* p;
p=(struct Test*);
int main()
{
printf("%p\n",p+0x1);
printf("%p\n",(unsigned long)p+0x1);
printf("%p\n",(unsigned int*)p+0x1);
return 0;
}
①0x00100014=0x100000+20个字节
②16进制转化为十进制1048576+1=10485767 0x00100001
③p类型强制转换为无符号整型指针,+1跳过一个整型,相当于跳过了4个字节
解释:因ptr是一个整型指针,-1,说明它向前跳过一个整型,指向10.
#include <stdio.h>
int main()
{
char *a[]={"work","at","alibaba"};//数组a里存放'w','a','a'首元素的地址
char **pa=a; //char* *pa=a;
pa++; //*pa说明pa是一个指针,pa++使得pa跳过一个char*的变量
printf("%s\n",*pa); //at
return 0;
}