GATE 2012 C Programming Questions: Switch and Storage-Class Analysis
Knowing C syntax is not enough when execution falls through a switch or a local variable survives a call. Trace three GATE CS 2012 C questions and compare the storage rules behind their outputs.
KnowledgeGate Team
Exam prep & CS education

You may recognise every C keyword yet get the output wrong because you stop at a case label or reuse the wrong variable. These three GATE CS 2012 C questions expose both habits. One switch trace and two storage traces reveal the rules behind the outputs and the revision gaps they expose.
What the GATE 2012 C questions test
The selected questions divide into two areas:
Topic | Tested skill | Questions | Items |
|---|---|---|---|
Control flow | Switch fall-through | Q1 | One |
Storage classes | Persistent local state and scope | Q2 and Q3, sharing code | Two |
The three GATE CS 2012 C questions group into switch control flow and storage-class state; the topic grouping and difficulty comments below are teaching assessments. Official past papers are available on the official GATE 2026 downloads page hosted by IIT Guwahati.
Use this historical review within your broader GATE CS preparation: identify the rule behind each answer before attempting another output question. For the earlier GATE 2015 C analysis focuses on value-versus-pointer parameters and recursive returns; this 2012 set isolates switch fall-through and storage duration.
Switch fall-through: follow execution beyond the matching case
Q1 uses this code:
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");
}(GATE 2012, switch fall-through solved page)
Execution enters at case 'A' and prints Choice A followed by a newline. There is no break, so it passes the empty B label and prints Choice B at C. It then passes D and E and executes default, printing No Choice.
The output is Choice A, a newline, then Choice BNo Choice. No space separates the last two strings. A case label selects entry; it does not end execution. Even default can be reached by fall-through.
This is straightforward once you scan for breaks. Revise the rule with Control Flow in C: If-Else, Loops, Switch, Solved Traces.
Static locals: keep separate boxes for identical names
Q2 uses this program:
#include <stdio.h>
int a, b, c = 0;
void prtFun(void);
int main(void) {
static int a = 1; /* Line 1 */
prtFun();
a += 1;
prtFun();
printf("\n %d %d", a, b);
return 0;
}
void prtFun(void) {
static int a = 2; /* Line 2 */
int b = 1;
a += ++b;
printf("\n %d %d", a, b);
}(GATE 2012, static-local walkthrough)
All three globals start at zero. Main's a starts at 1; the function's separate static a starts at 2.
First call: local
bstarts at 1. Prefix++bmakes it 2, so functionabecomes 2 + 2 = 4. Print4 2.Back in main: its own
abecomes 1 + 1 = 2.Second call: local
bstarts afresh at 1, then becomes 2. Staticaretains 4, so 4 + 2 = 6. Print6 2.Main prints its
aand globalb:2 0.
The numeric output rows are 4 2; 6 2; 2 0. Global a is shadowed. Function-local b never changes global b.
Auto and register: recompute the changed storage duration
For Q3, replace Line 1 with auto int a = 1; and Line 2 with register int a = 2;.
(GATE 2012, changed-declarations trace)
Each function call now starts with a = 2 and b = 1. Incrementing b gives 2, and adding it gives 2 + 2 = 4. Both calls print 4 2. Main still changes its own a from 1 to 2, while global b stays zero. The rows become 4 2; 4 2; 2 0.
register does not preserve state between calls or guarantee a physical CPU register. Review C Storage Classes, Structs and Enums: sizeof Questions if scope and lifetime still blur together.

What makes these questions easy to misread
Q1 needs one execution path. Q2 adds persistent state and name resolution. Q3 is more demanding than Q1 because changing declarations forces you to reconsider lifetime.
Repair these three common assumptions:
“A case exits automatically.” Mark every missing
breakbefore tracing.“Every a is the same variable.” Draw boxes named global a, main a and function a.
“Register a stays 4.” Reset it to 2 at each function entry.
Scope determines which declaration a name denotes. Lifetime describes how long its object exists. Track both separately.
Turn the 2012 traces into a repeatable practice session
Use this 30-minute 30-minute study session: 5 minutes annotating Q1, 10 tracing Q2, 5 tracing Q3, 5 comparing wrong reasoning and 5 recalling the rules without notes. The total is 5 + 10 + 5 + 5 + 5 = 30 minutes.
Vary the example by changing only function a's initializer to 3. In the static version, the first call computes 3 + 2 = 5 and prints 5 2; the second computes 5 + 2 = 7 and prints 7 2. Main still prints 2 0.
With the register initializer also changed to 3, both calls compute 3 + 2 = 5 and print 5 2, followed by main's 2 0. Log each error under three columns: mistaken assumption, first incorrect state and corrected rule.
The short version and your next step
Switch entry is not switch exit. Static local a persists; automatic and register locals in these examples initialise on each call. Identical names can denote different objects.
Reproduce both storage traces without looking at the options. If these rules still cause confusion, the C Language course offers structured concepts and MCQ practice. Return to these traces after revision and explain every printed value.
Keep learning
GATE 2012 Algorithm Questions: Topic Map and Worked PYQs
Turn the five currently tagged GATE 2012 Algorithm items into a revision plan, with worked concepts and the official Code A outcomes kept separate.
GATE 2014 C Programming Questions: Topic Analysis and Worked Traces
Trace seven selected GATE 2014 C questions to understand pointer input, double swaps, search boundaries and integer arithmetic. Use the mistakes to guide a focused revision session.
GATE 2017 C Programming Questions: Topic Breakdown and Worked Traces
Trace the values that decide the answer: copied pointer values, persistent static counts and recursive calls that never progress. This selected 2017 question set turns those mistakes into a focused revision session.
GATE 2016 C Programming Questions: Topic Map and Worked Traces
Trace caller state, shared static storage and array recurrences in selected GATE 2016 questions. Use the worked answers to identify what to practise next.





