Multiple choice technology programming languages

1)main() { int i = 1, j = 2; switch(i) { case i: printf(“GOOD”); break; case j: printf(“BAD”); break; }; }

  1. GOOD

  2. BAD

  3. ERROR

  4. NONE OF THESE

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

In a switch statement, case labels must be constant expressions, not variables. The code uses 'case i:' and 'case j:' where i and j are variables (int i=1, j=2). This is invalid syntax - case labels cannot be runtime variable values. The compiler will generate an error. The switch structure also has a semicolon after the closing brace, which is unusual but not an error.

AI explanation

In C, a switch statement's case labels must be constant expressions known at compile time — they cannot be variables. Here case i: and case j: use the variables i and j as labels, which is illegal, so the compiler rejects the code before it can run. Since it never gets to execute, neither "GOOD" nor "BAD" can print, and it's not a runtime exception either — it's caught at compile time.