int a[n]; is declared inside a function, with n supplied at run time. When is sizeof(a) evaluated, and what does it yield?
Correct answer
A. At run time, giving n times the element size, with no compile-time constant
19 views
A. At run time, giving n times the element size, with no compile-time constant
19 views
An array whose bound is not a constant expression is a variable length array, and sizeof applied to it is evaluated at run time, producing n times the element size in bytes. Ordinary arrays of constant size are measured at compile time, which is why sizeof is usually a constant expression. The catch is that the result has type size_t but the value cannot be used as a case label or in a static initialiser.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.