Array with size 0

后端 未结 4 1128
-上瘾入骨i
-上瘾入骨i 2020-11-27 03:59

Today I incidentally defined a two dimensional array with the size of one dimension being 0, however my compiler did not complain. I found the following which states that th

4条回答
  •  我在风中等你
    2020-11-27 04:53

    I ran this program at ideone.com

    #include 
    
    int main()
    {
        int a[0];
        int b[0][100];
        int c[100][0];
    
        std::cout << "sizeof(a) = " << sizeof(a) << std::endl;
        std::cout << "sizeof(b) = " << sizeof(b) << std::endl;
        std::cout << "sizeof(c) = " << sizeof(c) << std::endl;
    
        return 0;
    }
    

    It gave the size of all the variables as 0.

    sizeof(a) = 0
    sizeof(b) = 0
    sizeof(c) = 0
    

    So in the above example, no memory is allocated for a, b or c.

提交回复
热议问题