Can sizeof return 0 (zero)

后端 未结 10 1577
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 08:14

Is it possible for the sizeof operator to ever return 0 (zero) in C or C++? If it is possible, is it correct from a standards point of view?

10条回答
  •  余生分开走
    2020-11-28 09:10

    struct Empty {
    } em;
    
    struct Zero {
        Empty a[0];
    } zr;
    
    printf("em=%d\n", sizeof(em));
    printf("zr=%d\n", sizeof(zr));
    

    Result:

    em=1
    zr=0
    

提交回复
热议问题