Multiple choice general knowledge

Guess the Output? void main() { char ch='ABCD'; switch(ch) { case 'ABCD': printf("HelloABCD"); break; case 'A': printf("HelloA"); break; case 'B': printf("HelloB"); break; case 'C': printf("HelloC"); break; case 'D': printf("HelloD"); break; } }

  1. HelloD

  2. HelloC

  3. HelloB

  4. HelloA

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

The variable ch is declared as char but assigned 'ABCD' (a multi-character constant). In C, this implementation-defined behavior results in only the last character 'D' being stored (due to little-endian byte order). The switch matches case 'D' and prints 'HelloD'.