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
- Macro substitution directives. Example: #define
- File inclusion directives. Example: #include
- Conditional compilation directives. Example: #if, #else, #endif, #ifdef, #ifndef, #undef, etc
- 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:
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.
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
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
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
- .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.
- .obj file contains compiled code which can be understandable to the system only.
- .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.
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.