写出下面程序的输入结果:
#include <stdio.h>
struct BBB
{
long num;
char *name;
short int data;
char ha;
short ba[5];
}*p;
int main()
{
p = 0x1000000;
printf(" p+0x200=0x%08x\n", p+0x200);
printf(" (Ulong)p+0x200=0x%08x\n", (unsigned long)p+0x200);
printf("(char*)p+0x200=0x%08x\n", (char*)p+0x200);
printf("(short*)p+0x200=0x%08x\n", (unsigned short*)p+0x200);
printf("(int*)p+0x200=0x%08x\n", (unsigned int*)p+0x200);
return 0;
}
运行结果:
p+0x200=0x01003000
(Ulong)p+0x200=0x01000200
(char*)p+0x200=0x01000200
(short*)p+0x200=0x01000400
(int*)p+0x200=0x01000800
解答:
假设在32位CPU上,
sizeof(long) = 4 bytes
sizeof(char *) = 4 bytes<