Macro in C Language in Hindi
Macro in C Language in Hindi
C Language में macro define करने के लिए भी #define का इस्तेमाल करते हैं |
Syntax
#define Macro_name(Parameter_names(s)) action_using_Parameter_name;
यहां पर macro_name macro का नाम है parameter_name parameter का नाम होता है और एक्शन में हम कोई भी काम करते हैं | इसमें मैक्रो के नाम और started parentheses के बीच स्पेस नहीं दिया जाता है
Example
#define NUM 20;
#define SQ(x) ( x * x );
यहां पर पहले define statement में प्रोग्राम में जहां भी NUM नाम की वैल्यू मिलेगी compiler compile करने से पहले ही उसे हटा कर उसके जगह 20 लिख देगा और इसके बाद प्रोग्राम compile होगा |
जबकि दूसरे define statement में प्रोग्राम में जहां भी SQ(x) नाम की वैल्यू मिलेगी compiler compile करने से पहले ही उसे हटा कर उसके जगह उसका square लिख देगा और इसके बाद प्रोग्राम compile होगा |
example
#include <stdio.h> #define MAX(x,y) ((x) > (y) ? (x) : (y)) int main(void) { printf("Max between 20 and 10 is %dn", MAX(10, 20)); return 0; } Output
ax between 20 and 10 is 20
इस example में MAX नाम का macro define किया है और उसके साथ दो पैरामीटर भी इस macro में भेजा है और इसके action में दोनों नंबर में से बड़े नंबर को चेक किया जाता है और बड़ा नंबर return होता है।
C Preprocessor in detail