ProgrammingHardWipro · Accenture · Capgemini pattern

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int main(void) { char grade = 'B'; switch (grade) { case 'A': case 'B': printf("Good"); break; case 'C': printf("Average"); break; default: printf("Unknown"); } return 0; }

  1. A. Good
  2. B. GoodAverage
  3. C. Unknown
  4. D. Average

Correct answer: A. Good

Case 'A' has no break, so it falls through to share case 'B'\'s body; since grade is 'B', "Good" is printed either way.

More C Programming questions

Exams that ask this topic