JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

Preprocessor : Macro in hindi प्री प्रोसेसर में मैक्रो क्या है हिंदी c कंप्यूटर भाषा में macro in c language

प्री प्रोसेसर में मैक्रो क्या है हिंदी c कंप्यूटर भाषा में macro in c language , Preprocessor : Macro in hindi :-
इससे पहले के article मे , हमने file inclusion को पढ़ा |अब इस article मे हम macro को पड़ेगे जो की c language का महत्वपूर्ण tool है |
  1. Macro :
    Macro substitution एक येसी प्रोसेस होती जिसमे किसी प्रोग्राम के कोई keyword  को predefine value या expression (जो की दो  या दो से अधिक c टोकन से बनते है ) रेपल्स किया जाता है |Preprocessor का syntax होता है :

# define macro_name  value

इस syntax मे :
#define : ये macro Preprocessor को define करता है इसे macro definition  कहते है |
macro_nam : ये macro का नाम होता है जिसे value और expression के जगह प्रोग्राम मे use किया जाता है |
value /expression: ये  macro_name की value है या कोई expression होता है जिसका आउटपुट keyword की value होती है |

macro statement को main() function से पहले declare किया जाता है |अतः जब प्रोग्राम execute होता है तब सभी  macro_name की जगह  macro_name की value/expression की value replace हो जाती है |ये ध्यान रखन होते है की  macro_name और value के बीच space जरुर होना चाहिए | macro statement semicolon से terminate नहीं होता है |

C language मे अलग अलग प्रकार के macro होते है जिसमे तीन मुख्य होते है :-
1.Simple Macro
इस प्रकार मे  macro_name का replacement किसी constant value से होता है |जैसे
#define PI 22.7
#define COUNT 100
#define SIZE 450
#define CAPITAL “Jaipur”

उपर दिए गये उदाहरण मे , सभी macro statement मे macro_name कैपिटल मे लिखे गये है |किसी constant को capital letter मे लिखने से पहचना easy हो जाता है |

#define SIZE 12

इस उदहारण मे , प्रोग्रम मे जब जब SIZE लिखा जायेगा तब तब SIZE का रिप्लेसमेंट 12 से हो जायेगा |

उदहारण :
#include<stdio.h>
#include<conio.h>
#define PI 3.14
void main()
{
Printf(“Enter Radius”);
scanf(“%d”,&r);
printf(“Enter Height”);
scnaf(“%d”,&h);
Area = 2*PI*r*h;
Volume=PI*r*r*h;
printf(“Area=%f”,Area);
printf(“Volume=%f”,Volume);
getch();
}

Macro definition से , constant value के स्थान expression भी हो सकता है |इसका उदाहरण है :-
#define AREA   8*8
#define 2*PI      2*3.14
इन दोनों उदाहरन मे , AREA के स्थान 8*8=64 का replacement होगा और 2*PI के स्थान पर 6.28 replace होगा |
लेकिन जब किसी expression को macro definition मे use किया जाता है तभी उस expression को slove करने का कम्र पर ध्यान देना चाहिए क्योकि किसी expression का output expression के order पर निर्भर करता है |

किसी macro statement मे  expression को किसी भी expression से replace कर सकते है |जैसे
#define CONDITION if(a>b)
#define DISPLAY printf(“my name is “);
आदि |

C language मे c टोकन मे confuse हो सकते है |जैसे assignment operator और equal operator या and operator और address operator मे |इसलिए इस प्रॉब्लम को solve करने के लिए , हम सभी tokens को pre define कर देते है :
#define EQUAL              ==
#define ASSIGN              =
#define ADDRESS         &
#define AND                  &&
#define BACKLINE   printf(“\n”);
#define MOD                %

उदाहरण के लिए :
if(a MOD EQUAL 0)
{
printf(“perfect divid BACKLINE”);
printf(“Reminder is zero”);
}
else
{
printf(“Non Perfect divid BACKLINE”);
printf(“Reminder is non zero”);
}

2.Macro In function Argument

C language मे, function argument मे macro statement use कर सकते है |इसका syntax होता है :-

#define function_name(argument)    string

यहा पर :
function_name : ये उस function का नाम होता है जिसके आर्गुमेंट मे macro statement perform करना है |
argument: ये function का उस argument का नाम है जिसके जगह micro value assign होगी |
string : ये macro expression है जो function के argument मे replace होगा |

उदहारण के लिए:

#define  SQUARE(a)   a*a  // macro statement //

इस macro statement से ,SQUARE(a) के स्थान ओअर a*a replace हो जायेगा |जैसे :

Area of Square = SQUARE(a); // lets suppose a=10 //

तब इस statement से  Area of Square = a*a execute होगा  और Area of Square = 10*10 =100 होगी |

लेकिन जब area of square = SQUARE(x+y); perform होगा तब

इस statement से area of square = x+y * x+y * x+y ; execute होगा जो की error message देगा |इसलिए macro statement मे string के सभी members को () मे क्लोज किया जाता है |

#define  SQUARE(a)   ((a)*(a))  // macro statement //

इस statement के लिए ,area of square = ((x+y) * (x+y) * (x+y)) ; execute होगा जो की right आउटपुट देगा |

macro statement का function argument मे use काफी होता है |इसका comman उदहारण है :-
#define     MAXIMUM(x,y)                 ((x)>(y))?(x):(y))
#define     MINIMUM(x,y)                   ((x)<(y))?(x):(y))
#define     STRINGCMP(s1,s2)            (strcmp((s1),(s2))==0)
#define     STRINGCMP(s1,s2)            (strcmp((s1),(s2))>0)

3.Nesting of Macro
C language मे , किसी macro statement मे macro को use कर सकते है |इसलिए macro statement nested हो सकते है |
जैसे
#define A                  10
#define C                   34
#define B                  (A + 12 + C)

और
#define  PI                3.15
#define AREA(a)     2*PI*a;

Preprocessor जब तक nested macro statement को expand करेगा जब तब उस statement मे macro आते रहेगे |
जैसे उपर लिखे उदहारण -1 मे ,
B का replacement   (A + 12 + C) से होगा |
और बाद मे  (A + 12 + C)  मे , A और C का replacement 10और 34 से होगा |

और उदाहरण 2 मे ,
AREA (a) की जगह 2*PI *a replace होगे :
बाद मे  2*PI *a मे PI का replacement 3.14 से होगा |

2.Undefined Macro

जब यूजर किसी macro को प्रोग्रम के किसी specific part के लिए चाहता है तब इस Preprocessor का use किया जाता है |
इस Preprocessor मे macro statement को use करके उन्देफ़िएन कर सकते है |इसका syntax है :-

#undef macro_name;

यहा पर :
#undef  : ये  Preprocessor को declare करता है |
macro_name: ये उस macro का नाम होता है जिसे undefined करना है |

Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now