Preprocessor In C Programming

Posted on

Preprocessor

Preprocessor in C

 

Preprocessor is a program which can executed routinely earlier than passing the source program to compiler. This course of is named pre-processing. The preprocessor supplies the power for the inclusion of header information, macro expansions, conditional compilation, and line management.

preprocessor - Preprocessor In C Programming

The C Preprocessor isn’t part of compiler, it’s a separate program invoked by the compiler as the primary a part of translation.

Instructions utilized in preprocessor are known as preprocessor directives and so they start with pond “#” image and needs to be not ended with (;).

 

Outlined Proprocessor Directive

Proprocessor Directive may be place any the place in this system, however usually it place high of this system earlier than defining the primary perform.

Instance

Output

 

C language preprocessor directives

  • Macro substitution directives. instance: #outline
  • File inclusion directives. instance: #embody
  • Conditional compilation directive. instance: #if, #else, #ifdef, #undef
  • Miscellaneous directive. instance: #error, #line
Preprocessor Syntax Description
Macro #outline This macro defines fixed worth and may be any of the fundamental information sorts.
Header file inclusion #embody The source code of the file “file_name” is included in the primary program on the specified place
Conditional compilation #ifdef, #endif, #if, #else, #ifndef Set of instructions are included or excluded in source program earlier than compilation with respect to the situation
Different directives #undef, #pragma #undef is used to undefine an outlined macro variable. #Pragma is used to name a perform earlier than and after foremost perform in a C program

#ifdef, #else and #endif

“#ifdef” directive checks whether or not explicit macro is outlined or not. Whether it is outlined, “If” clause statements are included in source file. In any other case, “else” clause statements are included in source file for compilation and execution.

Instance

Output


#if, #else and #endif

“If” clause assertion is included in source file if given situation is true. In any other case, else clause assertion is included in source file for compilation and execution.

Instance

Output


undef

This directive undefines current macro in this system. In under program we first undefine age variable and once more it outline with new worth.

Instance

Output


pragma

Pragma is used to name a perform earlier than and after foremost perform in a C program.

Instance

Output

Clarification: Right here delay() perform are used for give delay or wait time for execution of code, this perform is current in dos.h header file. With the assistance of delay perform you possibly can see clearly stream of above program.