100% found this document useful (1 vote)
481 views1 page

Preprocessor Directives

This document discusses C preprocessor directives. It lists the common directives like #define, #include, #ifdef, and #undef. #define is used to define macros for constants or values. #include is used to include header files. #ifdef and related directives allow for conditional compilation. Preprocessor directives must begin with # and are processed before compilation. Examples show how directives can define macros, include files, undefine macros, and conditionally define macros.

Uploaded by

gopi9966957145
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
481 views1 page

Preprocessor Directives

This document discusses C preprocessor directives. It lists the common directives like #define, #include, #ifdef, and #undef. #define is used to define macros for constants or values. #include is used to include header files. #ifdef and related directives allow for conditional compilation. Preprocessor directives must begin with # and are processed before compilation. Examples show how directives can define macros, include files, undefine macros, and conditionally define macros.

Uploaded by

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

C Preprocessor Directives:

 Before a C program is compiled in a compiler, source code is processed by a


program called preprocessor. This process is called preprocessing.
 Commands used in preprocessor are called preprocessor directives and they
must be placed in definition section.
 All preprocessor commands begin with a pound symbol (#).
 A preprocessor directive should begin in first column.

Below is the list of preprocessor directives that C language offers.

S.no Preprocessor Syntax Description


1 Macro #define This macro defines constant value and can
be any of the basic data types.
2 Header file #include <file_name> The source code of the file “file_name” is
inclusion included in the main program .
3 Conditional #ifdef, #endif, Set of commands are included before
compilation #if, #else,  #ifndef compilation with respect to the condition
4 Other directives #undef,  #undef is used to undefine a macro

Preprocessors Examples:
Analyze the following examples to understand various directives.

e.g1: #define MAX_ARRAY_LENGTH 20


This directive tells the C to replace instances of MAX_ARRAY_LENGTH with 20.
Use #define for constants to increase readability.

e.g2: #include <stdio.h>


#include "myheader.h"
These directives tell the C to get stdio.h from System Libraries and add the text to the
current source file. The next line tells C to get myheader.h from the local directory and
add the content to the current source file.

eg3: #undef FILE_SIZE


#define FILE_SIZE 42
This tells the C to undefine existing FILE_SIZE and define it as 42.

e.g4: #ifndef MESSAGE


#define MESSAGE "You wish!"
#endif
This tells the C to define MESSAGE only if MESSAGE isn't already defined.

You might also like