Pre-processor statements पहले से बनाये गये (Pre-defined) programs या user के द्वारा बनाये गये वे Statements होते हैं जो Program में Source Code के पहले Process या Compile किये जाते हैं। Pre-processor हैश (hash sign) "#" के साथ प्रारम्भ होते हैं। Pre-processor directives निम्न प्रकार के हैं-
(1) Macro substitution directives.
(2) File inclusion directives.
(3) Conditional Compilation directives.
(1) Macro Substitution Directives - किसी C' program में Constant ( स्थरांक ) को define करने के लिये Macro Substitution Directives का उपयोग किया जाता है। Constant को define करने के लिये "#" के साथ "define" keyword का उपयोग किया जाता है तथा Constant का नाम Upper Case Letter (बड़े अक्षरों) में लिखा जाता है। Defined किये गये Constant को Program में केवल उसके मान (Value) को उपयोग में लाया जाता है, परन्तु उसके मान (Value) को बदला नहीं जा सकता।
Syntax :
# define CONSTANT NAME value
Ex:
# define PIE 6•141
# define DAYS 365
(2) File Inclusion Directives - किसी अन्य files में लिखे गये Functions या Macro
Definitions को अपने Program में शामिल (Include) करने के लिये file Inclusion Directives का उपयोग किया जाता है। किसी External Source File या Header file को अपने Program में शामिल करने के लिये "#" के साथ "include" keyword का उपयोग किया जाता है।
Syntax :
# include <external file name>
Ex:
# include <stdio.h>
# include <math.h>
(3) Conditional Compilation Direcitves - Code के Selection को चुनकर हटाने के लिये
Pre-processor एक विशेष Directive प्रदान करता है। यह विधि Conditional Comptlation कहलाती
है। Pre-processing Commands जैसे # ifdef तथा # endif को इंस्ट (insert) करके एक Source Code
के एक भाग पर Compiler स्किप (skip) प्राप्त करते हैं जिसका सामान्य रूप निम्न है-
# ifdef
mаcroname
<statement 1>;
# else
<statement 2>;
# endif
यदि macroname "# defined" है तब code block सामान्य रूप से क्रियान्वित होगा अन्यथा नहीं।
0 Comments