0% found this document useful (0 votes)
168 views2 pages

Preprocessor Unit 3 PDF

The preprocessor is a step that occurs before compilation in C programming. It defines and replaces tokens in the source code and inserts contents from other files. Preprocessor directives begin with # and are executed before compilation to define macros, include header files, and control compilation with conditional directives. Common preprocessor directives include #define for defining macros, #include for inserting header files, and #ifdef/#ifndef for conditional compilation.

Uploaded by

a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views2 pages

Preprocessor Unit 3 PDF

The preprocessor is a step that occurs before compilation in C programming. It defines and replaces tokens in the source code and inserts contents from other files. Preprocessor directives begin with # and are executed before compilation to define macros, include header files, and control compilation with conditional directives. Common preprocessor directives include #define for defining macros, #include for inserting header files, and #ifdef/#ifndef for conditional compilation.

Uploaded by

a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Preprocessor

In C programming language, preprocessor directive is a step performed before the actual source
code compilation. It is not part of the compilation. Preprocessor directives in C programming
language are used to define and replace tokens in the text and also used to insert the contents of
other files into the source file.

When we try to compile a program, preprocessor commands are executed first and then the
program gets compiled.

Every preprocessor command begins with # symbol. We can also create preprocessor commands
with parameters.

Following are the preprocessor commands in C programming language...

#define
#define is used to create symbolic constants (known as macros) in C programming language.
This preprocessor command can also be used with parameterized macros.
#include<stdio.h>
#include<conio.h>
#define PI 3.14
#define SQR(x) x*x //Parameterized Macro
void main(){
double radius, area ;
printf("Enter the radius: ");
scanf("%ld",&radius);
area = PI * SQR(radius) ;
printf("area = %ld",area);
}

#undef
#undef is used to destroy a macro that was already created using #define.

#ifdef
#ifdef returns TRUE if the macro is defined and returns FALSE if the macro is not defined.

#ifndef
#ifndef returns TRUE if the specified macro is not defined otherwise returns FALSE.
#if
#if uses the value of specified macro for conditional compilation.

#else
#else is an alternative for #if.

#elif
#elif is a #else followed by #if in one statement.

#endif
#endif is used terminate preprocessor conditional macro.

#include
#include is used to insert specific header file into C program.

#error
#error is used to print error message on stderr.

#pragma
#pragma is used to issue a special command to the compiler.
In C programming language, there are some pre-defined macros and they are as follows...
1. __ DATE __ : The current date as characters in "MMM DD YYYY" format.
2. __ TIME __ : The current time as characters in "HH : MM : SS" format.
3. __ FILE __ : This contains the current file name.
4. __ LINE __ : This contains the current line number.
5. __ STDC __ : Defines 1 when compiler compiles with ANSI Standards.

You might also like