Multiple choice technology programming languages

const int x = 5; int main(int argc, char** argv) { int x[x]; int y = sizeof(x) / sizeof(int); return 0; }

  1. 0

  2. 5

  3. 20

  4. undefined

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The global constant x=5 is declared at file scope. Inside main(), 'int x[x]' creates an array of size 5 (using the global x, not a VLA since x is a constant). The local x (the array name) shadows the global x within main. 'sizeof(x)' returns the size of the local array (5 * sizeof(int) = 20 on most systems). Dividing by sizeof(int) gives 5. The local array declaration doesn't affect the global constant.