Theory
वह line जो आप 10 बार type कर चुके हैं
अब तक हर program #include <stdio.h> से शुरू हुआ, बिना सोचे भरोसे पर type किया हुआ।
आज एक experiment: उस line को delete करके compile कीजिए। Compiler तुरंत ऐतराज़ करता है: "printf undeclared"। Line वापस लाइए, शांति लौट आती है।
यानी printf की पूरी ताक़त किसी तरह उसी एक line से आती है। कहाँ से, आता क्या है, और # से शुरू होने वाली lines को process कौन करता है? मिलिए preprocessor से, वह कारीगर जो compiler के पढ़ने से पहले आपका code edit करता है।
Theory
Toolbox और नियमों की दीवार
Mechanic हर काम के लिए spanner नहीं ढालता; वह कहता है "toolbox ले आओ"। #include <stdio.h> ठीक यही वाक्य है: standard input/output वाला toolbox ले आओ, ताकि printf और scanf मेज़ पर आ जाएँ। और #define workshop की दीवार पर पुता नियम है ("PASS_MARKS का मतलब 35"): एक बार पोत दिया, और हर कारीगर numbers रटने के बजाय दीवार पढ़ लेता है।
Theory
Header files, ठीक-ठीक
एक header file (.h) बनी-बनाई functions की declarations रखती है, compiler के लिए उनका introduction card।
- stdio.h (STanDard Input/Output):
printf,scanfऔर उनका परिवार। हर जगह standard। - conio.h (CONsole I/O):
getch()(एक keypress का इंतज़ार),clrscr()(screen साफ़ करना)। एक Turbo C ज़माने का, non-standard header: GCC और modern compilers इसे ship नहीं करते, और exams उम्मीद करते हैं कि यह asterisk आपको पता हो।
#include सचमुच compilation से पहले header का पूरा content आपकी file में paste कर देता है। इसी तरह printf जाना-पहचाना बनता है।
Theory
Preprocessor और #define
Preprocessor compiler से पहले चलता है। इसके directives # से शुरू होते हैं और कोई semicolon नहीं लेते, ये text के बारे में निर्देश हैं, statements नहीं।
#define PASS_MARKS 35 एक macro constant बनाता है: compile से पहले code का हर PASS_MARKS textually 35 से बदल दिया जाता है।
फ़ायदा क्या? code में बिखरा हुआ नंगा 35 एक magic number है: बिना समझाया और बदलने में ख़तरनाक। नाम वाला constant खुद को समझाता है, और जब university passing को 40 कर देती है, आप सिर्फ़ एक line बदलते हैं।
Practical
Marks program, अपनी नियम-पुस्तिका के साथ
#include <stdio.h>
#define PASS_MARKS 35
#define MAX_MARKS 100
int main() {
int marks = 78;
float percentage = (marks * 100.0) / MAX_MARKS;
char result = (marks >= PASS_MARKS) ? 'P' : 'F';
printf("Percentage: %f, Result: %c\n", percentage, result);
return 0;
}This example runs in Gri-Learn on the web, where you can edit it and see the output.
Quiz
ऊपर के program से #include <stdio.h> delete करके compile करें तो क्या होगा?
- Compiler रुक जाता है: printf undeclared है
- ठीक compile होता है पर कुछ print नहीं करता
- सिर्फ़ scanf बंद होता है, printf बच जाता है
- कुछ नहीं बदलता, stdio.h बस सजावट है
Show the answer
Compiler रुक जाता है: printf undeclared है
stdio.h printf की declaration, उसका introduction card, लेकर आती है। इसके बिना compiler को printf एक अजनबी की तरह मिलता है और वह "undeclared" कहकर रुक जाता है (या पुराने setups पर implicit-declaration warnings)। Header सजावट नहीं है; वही तरीक़ा है जिससे बनी-बनाई functions इस्तेमाल लायक बनती हैं। यही अंजाम scanf का भी है, दोनों stdio.h में रहते हैं।
Think first
छिपे bug को पकड़िए
एक student लिखता है: #define PASS_MARKS 35; (semicolon पर ध्यान दें) और बाद में if (marks >= PASS_MARKS)। Compiler if वाली line पर उलझाने वाला error दिखाता है। Preprocessor की तरह सोचिए: if वाली line बनी क्या?
Show the answer
Preprocessor semicolon समेत textually बदलता है: line बन जाती है if (marks >= 35;), और यही illegal है। Error असली ग़लती से दूर दिखता है, यही उसे क्रूर बनाता है। नियम: directives कोई semicolon नहीं लेते, क्योंकि वे text-editing के निर्देश हैं, C statements नहीं। यही bug spot-the-error का चहेता exam सवाल है।
Watch out
Marks कहाँ कटते हैं
#include या #define में semicolon जोड़ना (ऊपर वाला bug)। conio.h को standard कहना: यह Turbo C specific है; "non-standard" कहिए और mark बटोरिए। यह लिखना कि #include "function का code load करता है": वह declarations paste करता है; असली code LINKING पर आता है (pipeline याद कीजिए: इसीलिए printf का body library में रहता था, आपकी .obj में नहीं)।
Theory
अब तक का unit, जुड़ा हुआ
आज के code block को देखिए: pipeline, structure, variables, identifiers, types, operators और directives, इस unit का हर lesson उन 10 lines में है। अब भी यह program कुछ भी पूछ नहीं सकता: marks hard-coded हैं। अगले 2 lessons इसे कान और मुँह देते हैं: scanf और printf, C के input और output statements।
Summary
Key takeaways
- Header files बनी-बनाई functions की declarations रखती हैं; #include उन्हें paste करता है।
- stdio.h: printf/scanf (standard)। conio.h: getch/clrscr (Turbo C, non-standard)।
- Preprocessor compiler से पहले चलता है; directives # से शुरू और कोई semicolon नहीं।
- #define NAME value compile से पहले text बदलता है: नाम वाले constants, कोई magic numbers नहीं।
- एक #define बदलाव पूरे program को update करता है (PASS_MARKS 35 → 40)।
- Declarations headers से आती हैं; function के bodies linking पर आते हैं।
- याद रखने का hook: toolbox (#include) और नियमों की दीवार (#define)।