C Programming Miscellaneous Mistakes: 10 Traps in Macros, Types, Memory and Files
Ten common C traps are diagnosed at the right stage, from macro expansion and declarations to allocation, streams and undefined expressions. Each mistake includes the failure mechanism and a concrete repair.
KnowledgeGate Team
Exam prep & CS education

Miscellaneous C questions switch from preprocessing to declarations, storage, stream returns or operators without warning. Marks disappear when you calculate under the wrong rule. Each trap below names its cause, failure mechanism and repair. Use CS Fundamentals for Exams & Placements when a clue exposes a wider weak area.
C miscellaneous mistakes 1 and 2: classify before calculating
Mistake 1, treating miscellaneous as a fact bag. Why it happens: the last line resembles output arithmetic. What goes wrong: you calculate before spotting a macro, declaration, storage or stream clue. Do instead: classify it.
Clue | First action |
|---|---|
| Expand tokens |
| Resolve declarations |
| State storage |
| Trace returns |
Operators only | Apply precedence; check definedness |
Mistake 2, calling every failure run-time. Why it happens: all bad programs enter one bucket. What goes wrong: undeclared
missinginint y = missing + 1;requires a translation diagnostic. In an ordinary linked build,extern int total; int main(void) { return total; }without a definition fails while linking. Fromint x = 5;,if (x = 0)sets zero and takes theelsebranch, a logical error if comparison was intended. Do instead: identify the earliest failing stage.
C macro mistakes 3 and 4: evaluate the expansion

Mistake 3, reading a macro as a function. Why it happens:
SCALE(4)looks like a call. What goes wrong: with#define SCALE(x) x + 1,3 * SCALE(4)expands to3 * 4 + 1, so12 + 1 = 13, not15. Do instead: define#define SCALE(x) ((x) + 1). The result becomes3 * ((4) + 1) = 3 * 5 = 15.Mistake 4, assuming parentheses mean one evaluation. Why it happens: grouping looks safe. What goes wrong: let
MIN(a,b)be((a) < (b) ? (a) : (b)). Fromi = 4,MIN(i++, 10)tests4and leavesi = 5; the true arm yields5and leavesi = 6. Thusm = 5, i = 6. Do instead:static inline int min_int(int a, int b) { return a < b ? a : b; }evaluates once.min_int(i++, 10)givesm = 4, i = 5. C Programming Miscellaneous Formula Sheet: Macros, Memory, Types and File I/O is the compact reference for rule triggers and values; these ten traps explain why tempting answers fail across mixed C rules.
C type mistakes 5 and 6: derive values and state the model
Mistake 5, treating enum constants as positions from one. Why it happens: names look like ordered labels. What goes wrong:
enum state { READY = 2, RUNNING, FAILED = 7, RETRY };gives2, 3, 7, 8, not1, 2, 3, 4. Do instead: start at zero only when the first initializer is absent, add one after the previous value and restart after an explicit initializer.Mistake 6, adding member widths to predict structure size. Why it happens: padding is ignored. What goes wrong: when
sizeof(char) = 1,sizeof(int) = 4andintalignment is4,struct Pair { char c; int n; };occupies8bytes, not5.cis at offset0, offsets1..3are padding andnoccupies4..7. Do instead: usesizeof(struct Pair)on the stated implementation, never8as a universal guarantee.
C memory mistake 7: keep the allocated count
Mistake 7. Why it happens:
sizeof a / sizeof a[0]is copied onto amallocpointer. What goes wrong: whensizeof(int *) = 8andsizeof(int) = 4,n = 5; int *p = malloc(n * sizeof *p);requests5 * 4 = 20bytes for five integers. Butsizeof p / sizeof p[0]is8 / 4 = 2. A pointer carries no allocation count, so that ratio processes only two elements. Do instead: retainn = 5, checkp != NULL, loop withi < nand pass the count with the pointer. C Dynamic Memory Allocation, Macros, Scope and File Handling: 10 Mistakes handles those four topics in depth; allocation here is one checkpoint within a ten-trap diagnostic.
C file-handling mistake 8: test the conversion count
Mistake 8. Why it happens:
EOFis memorised as the only stop. What goes wrong: letmarks.txtcontain12 7 X 5. Inwhile (fscanf(fp, "%d", &x) != EOF) sum += x;, the first two calls return1, takingsumto12, then19. AtX,fscanfreturns0, consumes no integer and leavesx = 7. The true condition repeats stale7atX, so no finite final sum exists. Do instead: usewhile (fscanf(fp, "%d", &x) == 1) sum += x;. It stops at19; then handle malformed input. Miscellaneous C Programming: Storage Classes, Operators, Type Conversion, Macros and Bitwise, Fully Solved is the broader topic map; the input section isolates conversion-return failures.
C expression mistakes 9 and 10: group first, reject undefined traces
Mistake 9, reading shifts and addition left to right. Why it happens: they seem equal in precedence. What goes wrong: with
a = 4, b = 2, c = 3,a << b + cmeansa << (b + c). Calculateb + c = 5, then4 << 5 = 128. The invented(4 << 2) + 3 = 19is not the source grouping. Do instead: parenthesise by C precedence first.Mistake 10, forcing an undefined answer. Why it happens: you expect one tidy order. What goes wrong: from
i = 4,i++ + ++imodifiesitwice without sequencing, so neither its value nor finaliis defined. Do instead: label it undefined. For a deliberate sequence:left = igives4;i++makes5;++imakes6;right = igives6;z = 4 + 6 = 10. This is new code, not the original's meaning.

C miscellaneous mistakes: the 60-second audit and next step
Before submitting: classify the clue; find the earliest error stage; expand macros; count evaluations; derive enums and layout; carry allocation counts; test stream returns; apply precedence; reject undefined guesses.
Recheck the anchors: SCALE gives 13, repaired SCALE 15; enums give 2, 3, 7, 8; the stated structure is 8 bytes; pointer ratio 2 is not count 5; file sum is 19; shift result is 128; the unsequenced expression has no answer.
For practice, use C Language: Concepts, MCQs and Coding Questions for concepts, MCQs and coding.
Keep learning
C Dynamic Memory Allocation, Macros, Scope and File Handling: 10 Mistakes
Trace ten common C mistakes from incorrect allocation sizes to broken file-reading loops. Each diagnosis shows why it happens, the exact failure and the safer repair.
C Programming Miscellaneous Formula Sheet: Macros, Memory, Types and File I/O
Revise mixed C programming questions by classifying the rule first, then checking exact macro, memory, file and operator traces.
Functions in C Mistakes: Fix 11 Errors in Calls, Parameters and Recursion
Trace eleven common Functions in C errors without guessing the output. Learn what fails, why it fails, and the precise repair for each case.
Control Flow in C: 7 Mark-Losing Mistakes and Precise Fixes
Trace seven common C control-flow mistakes step by step, see exactly where execution changes course, and learn a short routine for checking every branch and loop.





