Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
A macro is a fragment of code which has been given a name. Whenever the name is used, it is replaced by the contents of the macro.
#define PI 3.14159 #define MAX_SIZE 100
#define SQUARE(x) ((x) * (x)) int s = SQUARE(5); // Becomes ((5) * (5))
Macros are simple text replacement and don't respect scope or type safety. In modern C++, prefer const for values and inline functions for logic.