Preprocessor In C Programming

Posted on

Preprocessor

Preprocessor in C

 

Preprocessor is a program which can executed mechanically earlier than passing the source program to compiler. This course of is known as pre-processing. The preprocessor gives the flexibility for the inclusion of header recordsdata, macro expansions, conditional compilation, and line management.

preprocessor - Preprocessor In C Programming

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

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

 

Outlined Proprocessor Directive

Proprocessor Directive could be place any the place in this system, however typically 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: #embrace
  • Conditional compilation directive. instance: #if, #else, #ifdef, #undef
  • Miscellaneous directive. instance: #error, #line
Preprocessor Syntax Description
Macro #outline This macro defines fixed worth and could be any of the essential information sorts.
Header file inclusion #embrace The source code of the file “file_name” is included in the principle 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 primary perform in a C program

#ifdef, #else and #endif

“#ifdef” directive checks whether or not specific 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 present 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 primary 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 movement of above program.