这个题目是我在群里看到大家讨论的,既然是讨论的了,那我就拿出来说说,因为笔试面试的时候,可能就会遇到这样的题目。
实例代码
#include "stdio.h"
#include "stdint.h"
struct Obj {
char a; //1
uint32_t b;//4
uint8_t c;//1
uint64_t d[0];//8
};
int main()
{
struct Obj Op;
printf("%d %dn",sizeof(Op),sizeof(Op.d));
return (0);
}
程序输出
16 0
--------------------------------
Process exited after 0.03048 seconds with return value 0
请按任意键继续. . .
这里比较令我们疑惑的是,d 的大小明明是 0,为甚结构体的大小会是 16呢?
调戏一下
看看下面代码的输出
#include "stdio.h"
#incl