赞
踩
- // 关于+1的各种情况
-
- #include <stdio.h>
-
- //默认对齐数为4
- // 结构体大小为16
- struct BBB
- {
- long A1;
- char A2;
- char A3;
- long A4;
- long A5;
- };
-
- int main()
- {
- struct BBB *p;
- p = (struct BBB *)0x100000;
- printf("%x\n", p + 0x1);//p是结构体指针,加1加了一个结构体大小,即0x100010
- printf("%x\n",(unsigned long) p + 0x1);// p是无符号长整型,加1即加1,即0x100001
- printf("%x\n", (unsigned long *)p + 0x1);// p是无符号长整型指针,加1即加一个指针大小4,即0x100004
- printf("%x\n",(char *)p + 0x1);// p是字符指针,加1即加字符指针大小1,即0x100001
- return 0;
- }
<img src="https://img-blog.csdn.net/20150508212801140?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。