How sizeof(array) works at runtime?

前端 未结 6 1753
心在旅途
心在旅途 2020-11-28 10:45

I have read that sizeof operator in C is interpreted at compile time and since at compile time compiler knows the array size and its type,sizeof is abled to compute the numb

6条回答
  •  抹茶落季
    2020-11-28 11:21

    sizeof is always computed at compile time in C89. Since C99 and variable length arrays, it is computed at run time when a variable length array is part of the expression in the sizeof operand.

    Same for the evaluation of the sizeof operand: it is not evaluated in C89 but in C99 if the operand is of variable length array type it is evaluated. For example:

    int n = 5;
    sizeof (int [n++]); 
    
    // n is now 6
    

提交回复
热议问题