Macros are used to define identifiers which can then be replaced the text they represent. We can define a macro using #define directive as shown below.
#define NAME "ABC"
int main()
{
char name[4] = NAME;
return 0;
}When the preprocessor processes the code, the replaces NAME with its value ABC. We can see this by running the command,
clang++ -ggdb -std=c++20 -E define.cpp -o define.i
If we see the content of macros.i, we see
# 1 "macros.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 518 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "macros.cpp" 2
int main()
{
char name[4] = "ABC";
return 0;
}Above example is one type of macro of text substitution. There is another of its type where we do not provide the replacement text. These identifiers are used in conditional compilation using macros.