# define in cpp code example
Example 1: define in cpp
#include <iostream>
// macro definition
#define LIMIT 5
int main()
{
for (int i = 0; i < LIMIT; i++) {
std::cout << i << "\n";
}
return 0;
}
Example 2: c++ what is #define
// #define is a macro that lets you use an alias name to
// make code more readable. During C++'s preproccessing stage, your macro
// will be replaced with the suitable code needed for proper compiling.
#include <iostream>
// used to define constants, types, functions and more....
#define SIZE 5
#define MacroInt int
#define getmax(a,b) ((a)>(b)?(a):(b))
int main(){
MacroInt myIntAsMacro = 7;
std::cout<< getmax(SIZE, myIntAsMacro); // will return 7
}