Introduction
C language में #include एक preprocessor directive है, जिसका उपयोग किसी header file की content को program में शामिल करने के लिए किया जाता है।
जब program compile होने से पहले preprocessor code को process करता है, तब #include directive के through दी गई file की सामग्री current program में जोड़ दी जाती है।
इससे हम पहले से लिखे गए useful functions, declarations और definitions का उपयोग कर सकते हैं।
उदाहरण के लिए:
printf()scanf()clrscr()- mathematical functions
इन सबका use करने के लिए related header files include करनी पड़ती हैं।
#include Directive Syntax
1. System Header File
#include <headerfile.h>
Example:
#include <stdio.h>
यह compiler को बताता है कि header file standard system library से ली जाए।
2. User-defined Header File
#include "headerfile.h"
Example:
#include "myheader.h"
यह user द्वारा बनाई गई header file को include करने के लिए use होता है।
#include Purpose
#include directive का मुख्य उद्देश्य है:
- ready-made functions का use करना
- code को modular बनाना
- program को simple और organized रखना
- same code को बार-बार लिखने से बचना
Example Program 1: Use of stdio.h Header File
#include <stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
Program Explanation
इस program में:
#include <stdio.h>
include किया गया है।
stdio.h का पूरा नाम है Standard Input Output Header File
इस header file में printf() और scanf() जैसे functions की declaration होती है।
Step-by-step working:
- Preprocessor
#include <stdio.h>को process करता है। stdio.hकी content program में जोड़ दी जाती है।- Compiler को
printf()function के बारे में जानकारी मिल जाती है। - Program
"Hello World"print करता है।
Output:
Hello World
Example Program 2: Input and Output using stdio.h
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("You entered: %d\n", num);
return 0;
}
Program Explanation
इस program में भी stdio.h include किया गया है क्योंकि:
printf()output देने के लिए use हुआ हैscanf()input लेने के लिए use हुआ है
Working:
- User से एक number input लिया जाता है
- वह value variable
numमें store होती है - फिर वही value screen पर print कर दी जाती है
Suppose Input:
Enter a number: 25
Output:
You entered: 25
Example Program 3: Use of math.h Header File
#include <stdio.h>
#include <math.h>
int main() {
float num = 16, result;
result = sqrt(num);
printf("Square root of %.2f = %.2f\n", num, result);
return 0;
}
Program Explanation
इस program में दो header files include की गई हैं:
#include <stdio.h>
#include <math.h>
इनका काम:
stdio.h→printf()के लिएmath.h→sqrt()function के लिए
sqrt() function किसी number का square root निकालता है।
Working:
num = 16sqrt(16)calculate होता है- result
4.00आता है - output print होता है
Output:
Square root of 16.00 = 4.00
System Header File vs User-defined Header File
| Point | System Header File | User-defined Header File |
|---|---|---|
| Syntax | #include <file.h> | #include "file.h" |
| Location | Compiler library | User की बनाई file |
| Example | stdio.h, math.h | myfile.h |
Common Header Files in C
| Header File | Use |
|---|---|
stdio.h | Input/Output functions |
conio.h | Console related functions |
math.h | Mathematical functions |
string.h | String functions |
stdlib.h | Utility functions |
ctype.h | Character handling functions |
Important Points
#includepreprocessor directive है- यह compilation से पहले file को include करता है
- header files functions की declarations provide करती हैं
- बिना सही header file include किए function use करने पर error आ सकता है
Advantages of #include Directive
1. Code reuse
पहले से बने functions का use कर सकते हैं
2. Time saving
हर function खुद से लिखने की जरूरत नहीं
3. Better organization
program modular बनता है
4. Easy maintenance
code structured रहता है
Conclusion
#include directive C language का बहुत important हिस्सा है।
इसका उपयोग header files को program में जोड़ने के लिए किया जाता है ताकि हम standard library या user-defined functions का use कर सकें।
यह program को simple, modular और reusable बनाता है।stdio.h सबसे common header file है, क्योंकि input-output के लिए इसका use लगभग हर program में होता है।