Can sizeof return 0 (zero)

后端 未结 10 1542
爱一瞬间的悲伤
爱一瞬间的悲伤 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 08:58

    Here's a test, where sizeof yields 0

    #include 
    
    void func(int i)
    {
            int vla[i];
            printf ("%u\n",(unsigned)sizeof vla);
    }
    
    
    int main(void)
    {
    
            func(0);
            return 0;
    }
    

提交回复
热议问题