📘 Lesson · Lesson 60
Macros & Preprocessor
Macros & Preprocessor
What is the Preprocessor?
💡 Note
The preprocessor runs before compilation. Directives start with # — like #include and #define.
Macros
C
#include <stdio.h>
#define PI 3.14
#define SQUARE(x) ((x)*(x))
int main() {
printf("%.2f\n", PI); // 3.14
printf("%d\n", SQUARE(5)); // 25
return 0;
}Output:
3.14 25
3.14 25
Summary
#definecreates constants and macro functions;#includeadds files.- Macros are replaced by the preprocessor before compiling.
Preprocessor क्या है?
💡 Note
Preprocessor compilation से पहले चलता है। Directives # से शुरू होती हैं — जैसे #include और #define।
Macros
C
#include <stdio.h>
#define PI 3.14
#define SQUARE(x) ((x)*(x))
int main() {
printf("%.2f\n", PI); // 3.14
printf("%d\n", SQUARE(5)); // 25
return 0;
}Output:
3.14 25
3.14 25
सारांश
#defineconstants और macro functions बनाता है;#includefiles जोड़ता है।- Macros compile से पहले preprocessor द्वारा replace होते हैं।