Storage Classes, Structures and Enums in C: 7 Mistakes That Cost Marks
Knowing the definitions is not enough when a C question mixes scope with lifetime, padding with member size, or enum positions with values. Repair seven common mistakes through exact traces.
KnowledgeGate Team
Exam prep & CS education

You may remember that static retains a value, a structure groups members, and an enum names integers, yet still get a code-output or sizeof question wrong. The usual cause is mixing up scope with lifetime, object copying with pointee copying, or a label's position with its numeric value. Here are seven concrete mistakes, each repaired through a small trace. At the time of writing, KnowledgeGate's question bank included over 90 published questions across storage classes, structures and enums, giving you enough material to practise each rule in more than one form.
1. Storage classes in C: scope is not lifetime
Mistake 1 begins when saved and fresh are both declared inside tick(), so they appear to be recreated on every call.
void tick(void) {
static int saved = 2;
int fresh = 2;
saved += 3;
fresh += 3;
printf("%d %d\n", saved, fresh);
}
int main(void) {
tick();
tick();
}The first call prints 5 5. The second prints 8 5. Both names have block scope, but saved has static storage duration and its initialisation occurs once. fresh has automatic storage duration and is initialised to 2 on every call.
The fix is to ask two separate questions for every identifier: where can its name be used, and how long does its object exist? Storage Classes in C: Scope, Lifetime and Exam Traps develops that distinction through scope, duration, and linkage.
2. extern, file scope and shadowing: trace the object, not the spelling
Mistake 2 is treating every declaration called total as the same local variable, or assuming extern creates a new integer.
static int total = 5;
void add(void) {
extern int total;
total += 2;
}
int read_total(void) { return total; }
int main(void) {
int total = 20;
add();
printf("%d %d\n", total, read_total());
}The output is 20 7, not 22 22 or 20 5. The local total shadows the file-scope name only inside main. The prior file-scope static declaration gives its object internal linkage. The block-scope extern declaration in add refers to that same object and creates no new one. Mark each declaration's scope and linkage before tracing assignments.
3. Structure size: member totals ignore alignment padding

Mistake 3 is adding member sizes and concluding that sizeof(struct Record) is 1 + 4 + 2 = 7.
Assume char size/alignment 1/1, short 2/2, int 4/4, with no packing pragmas:
struct Record {
char code;
int marks;
short rank;
};code occupies byte 0. Bytes 1-3 are padding so that marks can occupy 4-7. rank occupies 8-9, followed by tail padding at 10-11. The strictest alignment is 4, so the complete size is 12 bytes.
Reordering the same members changes the layout:
struct BetterOrder {
int marks;
short rank;
char code;
};Here, marks occupies 0-3, rank occupies 4-5, code occupies 6, and byte 7 is tail padding. The size is 8 bytes. Align each member's starting offset, then round the total to a multiple of the strictest alignment. In real code, confirm with offsetof and sizeof, because the C standard does not fix these choices. See Structures and Unions in C: Padding and Alignment for a fuller treatment.

4. Structure assignment: fields copy, but a pointer still aliases its pointee
Mistake 4 is reading “structure assignment copies everything” as a recursive deep copy of objects reached through pointers.
int n = 7;
struct Box { int value; int *alias; };
struct Box a = {2, &n};
struct Box b = a;
b.value = 5;
*b.alias = 9;Printing a.value, b.value, *a.alias, *b.alias gives 2 5 9 9. Assignment copies each member value. Changing b.value leaves a.value at 2, but copying alias copies an address. Both pointers still reach the same n, now 9. Draw separate boxes for a and b, then arrows to one pointee.
Mistake 5 is choosing the access operator from habit. If q is a struct Box *, q.value is invalid. So is *q.value, because . binds before unary *. Use q->value or (*q).value. For the object a, use a.value.
5. Enum values: explicit initialisers break position-based guessing
Mistake 6 is counting enumerator positions from zero even after an explicit initialiser:
enum Status {
FAIL = -1,
IDLE,
READY = 4,
RUNNING,
DONE = RUNNING + 2
};Write each value before evaluating an expression. FAIL = -1, so IDLE = 0. READY resets the running value to 4, making RUNNING = 5 and DONE = 5 + 2 = 7. Printing them in order produces -1 0 4 5 7.
Mistake 7 is treating bit-mask enumerators as mutually exclusive ordinal states. With READ = 1, WRITE = 2, and EXECUTE = 4, the expression mode = READ | EXECUTE gives 1 | 4 = 5. Then mode == READ evaluates to 0, while (mode & READ) != 0 evaluates to 1. Decide whether an enum describes one state or combinable flags. Use equality for a state and bit tests for flags.
6. C output questions: use a four-pass mistake check
Use the same routine on every mixed C question:
Annotate each name with scope, storage duration, and linkage where relevant.
Write the assumed sizes and alignments before drawing structure offsets.
Separate copied pointer addresses from the values they point to.
Expand every enum constant to an integer before applying equality or bitwise operators.
A code-output MCQ can combine a retained static value with shadowing. A sizeof question can hide tail padding. A statement question can test legal structure assignment, while an enum expression can mix explicit values and flags. Practise the tracing method with C Programming Fundamentals: Worked Examples for GATE, then use CS Fundamentals for related subject notes.
7. Storage classes, structures and enums: the short correction sheet
Keep seven corrections ready: block scope does not imply automatic lifetime; extern does not create a new local object; sizeof(struct) is not merely the sum of members; pointer members make structure copies shallow at the pointee boundary; . and -> depend on an object versus a pointer; enum values follow explicit initialisers; bit flags require bit tests.
If these rules still feel disconnected, the C Programming course is a practical next step for rebuilding them in sequence.
Keep learning
Storage Classes, Structures and Enums in C: Formula Sheet with Worked Revision
Revise C declarations through three separate axes, then test them with a two-call trace, a byte-layout calculation and an enum sequence.
Storage Classes, Structures and Enums in C: Worked Examples for GATE Output and sizeof Questions
Trace static variables across calls, calculate structure padding byte by byte, compare structures with unions, and follow enum values after an explicit jump.
Storage Classes in C: Worked Examples for Scope, Lifetime, Linkage and GATE Traps
Learn what auto, register, static and extern actually control. Classification tables, two-file code and exact traces turn similar-looking declarations into predictable C behaviour.
Miscellaneous C Programming: Storage Classes, Operators, Type Conversion, Macros and Bitwise, Fully Solved
Learn the C rules behind predict-the-output questions, then apply them to five fully worked patterns covering static storage, precedence, conversions, macros and bits.





