#include Directive

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:

  1. Preprocessor #include <stdio.h> को process करता है।
  2. stdio.h की content program में जोड़ दी जाती है।
  3. Compiler को printf() function के बारे में जानकारी मिल जाती है।
  4. 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:

  1. User से एक number input लिया जाता है
  2. वह value variable num में store होती है
  3. फिर वही 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.hprintf() के लिए
  • math.hsqrt() function के लिए

sqrt() function किसी number का square root निकालता है।

Working:

  1. num = 16
  2. sqrt(16) calculate होता है
  3. result 4.00 आता है
  4. output print होता है

Output:

Square root of 16.00 = 4.00

System Header File vs User-defined Header File

PointSystem Header FileUser-defined Header File
Syntax#include <file.h>#include "file.h"
LocationCompiler libraryUser की बनाई file
Examplestdio.h, math.hmyfile.h

Common Header Files in C

Header FileUse
stdio.hInput/Output functions
conio.hConsole related functions
math.hMathematical functions
string.hString functions
stdlib.hUtility functions
ctype.hCharacter handling functions

Important Points

  • #include preprocessor 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 में होता है।

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top