5.1.27 · D3 · HinglishC Programming

Worked examplesPreprocessor directives — #define, #ifdef, #ifndef, #include guards

2,603 words12 min read↑ Read in English

5.1.27 · D3 · Coding › C Programming › Preprocessor directives — #define, #ifdef, #ifndef, #include


Scenario matrix

Is topic ke har problem ka jawab inhi case classes mein se ek mein aata hai. Neeche ke worked examples mein har ek ko us cell ke saath tag kiya gaya hai jise woh cover karta hai, aur milkar woh har cell ko cover karte hain.

# Case class Kya galat ho sakta hai / kya dhyan dena hai Example jo ise cover karta hai
A Object-like macro, simple constant text swap, preprocessor dwara koi arithmetic nahi Ex 1
B Function-like macro, precedence danger missing parens grouping badal dete hain Ex 2
C Function-like macro, side-effect / double-eval argument do baar evaluate hota hai Ex 3
D #ifdef / #ifndef branch selection (defined) kaun sa text bachta hai Ex 4
E #ifndef default value override external -D built-in default se jeet jaata hai Ex 5
F Include guard — paste-twice degenerate case doosra paste poora delete ho jaata hai Ex 6
G Degenerate / zero input ek macro ko empty arg, 0, macro-defined-as-nothing Ex 7
H Real-world word problem (cross-platform) real target par sahi branch chunna Ex 8
I Exam twist — trailing semicolon + nesting classic arr[MAX;] aur stacked conditions Ex 9
J Limiting case — macro jo doosre macro mein expand hoti hai (chained) rescanning, recursion limits Ex 10
Figure — Preprocessor directives — #define, #ifdef, #ifndef, #include guards

Worked examples






Figure — Preprocessor directives — #define, #ifdef, #ifndef, #include guards





Recall Rapid self-test (answers chhupao)

Ex1 RATE*8+2 ::: 42 Ex2 AREA(2+3,4) with w*h body ::: 14 (fix se 20 milta hai) Ex3 MAX2(i++,3) from i=5 gives m,i ::: m=6, i=7 (double evaluation) Ex5 with -DBUFFER_SIZE=1024 ::: buf mein 1024 bytes hain Ex6 struct guard ke saath paste, do baar include ::: ek baar appear hoti hai Ex8 NEWLINE on Linux ::: "\n" Ex9 fixed extra ::: 11 Ex10 TWICE(A) through chain ::: 14