Pre-Processing in C

Pre-Processing Directives in C

In this article, I am going to discuss the Pre-Processing Directives in C with Examples. Please read our previous article, where we discussed Functions in C. As part of this article, you will learn what is Pre-Processing in C, it’s type, and when and how to use Pre-Processing in C Program with examples.

What is pre-processor?

Pre-processing is a program that will be executed automatically before passing the source program to the compiler. Pre-processing is under the control of pre-processor directives. All preprocessor directives start with a pound (#) symbol & should be not ended with semicolon (;). When we are working with pre-processor directives, it can be placed anywhere within the program but recommended to place on top of the program before defining the first function.

How many types of pre-processor detectives are there in the c programming language?

In C programming language pre-processor directives are classifieds into 4 types such as

  1. Macro substitution directives. Example: #define
  2. File inclusion directives. Example: #include
  3. Conditional compilation directives. Example: #if, #else, #endif, #ifdef, #ifndef, #undef, etc
  4. Miscellaneous directives. Example: #pragma, #error, #line, etc
How the executable file created in C programming language?

When we are working with any kind of C application, we are required to perform 4 steps:

  1. Editing
  2. Compiling
  3. Linking
  4. Loading
Editing:

It is a process of constructing the source program and saving with .c extension. .c file contains the source code of the application i.e. user-readable format data. To perform the editing process, we required any kind of text editors like notepad, word pad, or any other C language-related IDE.

Compiling:

It is a process of converting high-level programming language code into the machine-readable data i.e. object code or compiled code. When the compilation process will complete then we will get .OBJ file. .OBJ file contains the compiled code. To compile any C-program we required C-programming language compiler like GCC, Turbo-C, etc

Linking:

It is a process of combining all obj files of the current project along with standard lib or obj files to construct an executable file. When the linking process is successful then the automatically executable file is generated with .exe extension. .exe file contains the native code of the operating system

Loading:

It is a process of carrying the application file (.exe file) from secondary storage area to primary memory i.e. RAM. Editing, compiling, and linking is under control of IDE, and loading is under control of the Operating System. When we are working with any C application, it creates 5 types of files i.e. .c, .BaK, .exe, .I, .obj

  1. .c, .I, .Bak contains user-readable format data i.e. source format. Generally, .I file contains extended source code which is constructed after pre-processing.
  2. .obj file contains compiled code which can be understandable to the system only.
  3. .exe file contains the native code of OS.

For a better understanding of the above-discussed points, please have a look at the following diagram.

Pre-Processing in C

In the next article, I am going to discuss Macro Substitution Directives in C language. Here, in this article, I try to explain Pre-Processing Directives in C. I hope you enjoy this Pre-Processing directive in C article. I would like to have your feedback. Please post your feedback, question, or comments about this article.

Leave a Reply

Your email address will not be published. Required fields are marked *