C++ Pre-processors

There are mainly four types of Pre-processor directives in C++ programming language, and they are: -

  1. Macros
  2. File Inclusion
  3. Conditional Compilation
  4. Other directives

Macros

The macros in C/C++ programming language are one of the most exciting concepts. These are the sentences written in C++ code with the help of #define, and whenever the allocated variable is called, the value associated will be swapped and executed.

C++ code

Output:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Macros with parameters C++ code

Output:

The area of the object similar to a rectangle is: 10850

2. File Inclusion

This is one of the often-seen C++ Preprocessors as we use it daily, including some built-in libraries essential for our daily basic programming needs.

Syntax

3. Conditional Compilation

The Conditional unique compilation and preserved directives are an essential and integral part and parcel type of directives that help us to compile and run the specific portion of the program or a code snippet seamlessly to skip the compilation of some particular part of the program based on some conditions.

Syntax

4. Other directives

Apart from the directives in our C++ programming language, there are two mostly unknown and not so used directives #undef Directive, #pragma startup and #pragma exit: directives. Their implementation is given below

C++ code

Output:

/tmp/ Lj D4 TT sh NS.o
Hello, coder on javaTpoint.com. We are inside the int primary () function now.

C++ code

Output:

hello coder we are currently inside the function_1_is()
hello coder, we are currently inside the int main() function
hello coder we are currently inside the function_2_is()

Happy Coding!