Read in Hindi
Read in English

Now we have learned basics of C, but yet we do not know why we #include <stdio.h> is written on the 1st line of every program. Today we will know things related to this.

In the beginning we learned that after we write a program, computer converts it to machine language. That process is called compilation. Compilation process goes through many steps. Today we will learn about those steps then why we write #include <stdio.h> in the beginning of every program.

We know that printf is a function. This function is defined(declared) in stdio.h file. When program is compiled, in 1st step compiler replaces #include <stdio.h> with content of stdio.h file. This process is called pre-processing. By doing this program gets to know definition of printf function, hence can run this function successfully otherwise it will give compile error that printf function not defined.

stdio means Standard Input and Output. In this file(stdio.h) all function used for input/output are defined. printf used to print output on console whereas scanf used to read input from console. Both functions are declared in stdio.h file.

Pre-processing

In a program any line starting with # is called pre-processor. In 1st step of compilation process compiler modifies them. #include is a pre-processing directive which replaces it with content file given. There are some more pre-processing directive which are described below.

#define ABC 1
#define is used to define constant. If #define ABC 1 is present in program, in 1st step of compilation ABC will be replaced with 1 in the program. #define is called macro too.

#define SUM(a,b) (a+b)
This is also a macro which can take parameter. If use this in program, SUM(x,y) will be replaced with (x+y) in the program.

#ifdef xyz
...
#endif
If xyz is defined anywhere using #define then program between #ifdef and #endif will be compiled otherwise it will be removed.

Note: One pre-processor should be written in one line only and nothing else in that line.
We are seeing #include from beginning. Below we will see example of some other pre-processor.

#include <stdio.h>
#define AREA(r) (PI*r*r)
#define PI 3.14159

int main() {
  int rad = 10;
  float area = AREA(rad);
  printf("Area of circle is %f\n", area);

  scanf("%d", &r);
  return 0;
}

In the program given above AREA(rad) will be replaced with (PI*rad*rad) and then in this PI will be replaced with 3.14159. Note that it is not same as function call. In function call return value should be assigned to area but here AREA(rad) is replaced with (3.14159*rad*rad) and answer is calculated here itself without any function call, that is assigned to area, but effect is same as function call.
हमने C का basic जान लिया है, परन्तु #include <stdio.h> क्यों लिखते हैं ये नहीं जाना. आज इस यह और इससे related बाते जानेंगे.

शुरू में हमने पढ़ा था कि हम program लिखते हैं, उसके बाद computer उसे machine की भाषा में बदलता है. इस प्रक्रिया(process) को कहते हैं program को compile करना. यह compile करने कि प्रक्रिया कई चरणों(steps) में होती है. आज हम इसके पहले step को जानेंगे. इसके साथ ही हम यह भी जान लेंगे कि हर program के शुरू में #include <stdio.h> क्यों लिखते हैं.

हम जानते हैं कि printf एक function है. यह function stdio.h नाम की file में defined (declared) है. जब program को compile करते हैं तो पहले step में compiler #include <stdio.h> को हटाकर उसकी जगह stdio.h file का content डाल देता है. इस process को pre-processing कहते हैं. ऐसा करने से program को यह पता चल जाता है कि printf function कहाँ किस तरह से defined है और उसे किस तरह से run करना है. अन्यथा error आ जायेगी कि printf function नहीं मिल रहा.

stdio का मतलब है Standard Input and Output. इस file(stdio.h) में वो सब function defined हैं जो input/output लेने के काम आते हैं. printf output को print करने के काम आता है जबकि scanf input लेने के काम आता है. दोनों ही function stdio.h file में defined हैं.

Pre-processing

किसी भी program में जो line # से start होती हैं उन्हें pre-processor कहते हैं. Compiler पहले step में इन्हें process करके program को modify कर देता है. जैसा कि ऊपर बताया गया है. #include एक pre-processing directive हैं जो उसके बाद लिखे गए file के content को उसकी जगह लिख देता है. कुछ और भी pre-processing directive होते हैं जिनके बारे में नीचे बताया गया है.

#define ABC 1
#define किसी भी constant को define करने के लिए उपयोग में लाया जाता है. #define ABC 1 लिखने पर जहाँ जहाँ program में ABC लिखा होगा उसकी जगह 1 compiler पहले step में 1 लिख देगा. #define को macro भी कहते हैं.

#define ADD4(a) (a+4)
यह भी एक macro है जो parameter ले सकता है. इसका use करने पर program compile करने के 1st step में जहाँ भी ADD4(x) लिखा होगा वहां (x+4) लिख जायेगा जहाँ x कुछ भी हो सकता है, variable या कुछ और. जैसे कि अगर ADD4(5) लिखा है तो उसकी जगह (5+4) हो जायेगा.
#ifdef xyz
...
#endif
अगर हमने #define का use करके xyz कहीं define किया है तो #ifdef और #endif के बीच में लिखा हुआ program compile होगा अन्यथा दोनों के बीच लिखा हुआ program हटा दिया जायेगा.

Note: एक pre-processor एक line में ही लिखा जाता है. एक line में एक से ज्यादा pre-processor या एक pre-processor एक से ज्यादा line में नहीं लिख सकते, अन्यथा program नहीं चलेगा.
#include का example हम शुरू से देखते आये हैं. नीचे अन्य pre-processor commands के example भी देखते हैं.

#include <stdio.h>
#define AREA(r) (PI*r*r)
#define PI 3.14159

int main() {
  int rad = 10;
  float area = AREA(rad);
  printf("Area of circle is %f\n", area);

  scanf("%d", &r);
  return 0;
}

ऊपर दिए गए program में AREA(rad) की जगह (PI*rad*rad) और फिर इसकी जगह (3.14159*rad*rad) हो जायेगा. ध्यान दे कि यह function call करने के बराबर नहीं है. function call करने में function द्वारा return की हुई value area को मिल जाती पर यहाँ पर AREA(rad) कि जगह (3.14159*rad*rad) लिख दिया जाता है और बिना कोई function call किये यहीं से जो value calculate होती है वो area को मिल जाती है.
अगर आपको यह लेख पसंद आया हो तो अपने दोस्तों को भी बताएं क्योंकि ये उनके लिए भी उपयोगी सिद्ध हो सकता है!! नीचे दिए गए link के माध्यम से इसे आसानी से facebook twitter और Google Buzz पर भी Share कर सकते हैं.