Skip to content
Official PYQ · 2012

GATE CS 2012 Q3 — Programming in C

Explain with AI

What will be the output of the following C program segment?

 char inChar = 'A';
    switch ( inChar ) {
       case 'A' : printf ("Choice A \ n");
       case 'B' :
       case 'C' : printf ("Choice B");
       case 'D' :
       case 'E' :
       default : printf ("No Choice"); 
    }

Marks were awarded to all candidates for this question. It is not scored as a normal quiz.

View worked solution

Marks to all

This question was awarded Marks to All (MTA) by GATE due to typographical errors in the options and code. Below is the detailed step-by-step execution and explanation of the behavior.

1. Concept of Switch-Case Fall-Through

In C, the switch statement executes the matching case label. If a case block does not end with a break statement, the execution continues ("falls through") into the subsequent cases and the default block, regardless of whether those case labels match the switch expression.

2. Step-by-Step Execution

  • Initialization: char inChar = 'A';
  • The switch (inChar) matches case 'A'.
  • It executes:
    printf ("Choice A \ n");
    (Assuming \ n is a typo for the newline character \n, this prints Choice A followed by a newline).
  • Since there is no break statement at the end of case 'A', the control falls through to case 'B' and then case 'C'.
  • It executes:
    printf ("Choice B");
  • Again, there is no break statement, so control falls through case 'D', case 'E', and finally the default block.
  • It executes:
    printf ("No Choice");

3. Expected Output vs Options

Combining the outputs sequentially, the exact output of the program is:

Choice A 
Choice BNo Choice

Why Marks to All (MTA) was given:

  1. There is no space printed between Choice B and No Choice in the actual execution, but Option C includes a space: Choice B No Choice.
  2. The code contains a space inside the escape sequence (\ n instead of \n), which is syntactically a literal backslash and space in many contexts rather than a newline.

Because of these discrepancies, none of the options are technically correct, and full marks were awarded to all candidates.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Programming in C questions