SlideShare a Scribd company logo
1 of 30
Preprocessor Directives in
C
Definition
 A preprocessor is a program that
processes our source program before it
is passed to the compiler.
 The preprocessor works on the source
code and creates “expanded source
code”.
 The preprocessor offers several features
called preprocessor directives.
 Each of theses preprocessor directives
begin with a # symbol.
 The directives can be placed anywhere
in a program but most often placed at the
beginning of the program,before the
function definition.
Preprocessor directives are executed before
compilation.
 The various preprocessor directives
are as follows:
1)Macro Expansion (#define)
II)File Inclusion(#include)
III)Conditional Compilation(#ifdef -#endif)
IV)Miscellaneous Directives
(#undef,#pragma-startup,exit,warn)
Macro Expansion
 A “macro” is a fragment of code which
has been given a name.
 Wherever the name is used,it is
replaced by the contents of the macro.
 There are two kinds of macros which
are as follows:
I)Object-like macros resemble data
objects
II)Function-like macros resemble function
calls.
Object –like Macros
 The object-like macro is an identifier
that is replaced by value.
 It is widely used to represent numeric
constants.
 It is called object-like because it looks
like a data object in code that uses it.
 Syntax:
#define identifier replacement-text
Examples
#define x 4 x=identifier 4=replacement-text
void main()
{
int a;
a=x;
}
#define pi 3.14 pi=identifier
3.14=substitute
void main()
{
float r=6.25,area;
area=pi*r*r;
printf(“Area of circle=%f”,area);
}
Note:
 To create macros with the #define
directive,the syntax for macros is:
#define macro macro
expansion replacement list
 #define directive can be used as follows:
I) It can be used to define operators like:
#define AND &&
#define OR ||
II)it could be used even to replace a
condition:
# define AND &&
#define ARRANGE (a>25 AND a<50)
III) It could be used to replace even an
entire C statement like:
# define FOUND printf(“Hello World”)
Function-like Macro
 It looks like a function call & can be
defined with the # define directive but
with a pair of braces or parenthesis
immediately after the macro name.
 For Example:
#define Area(x) 3.14* r*r
Macro with arguments
 Function –like macros can take
arguments just like true functions.
Difference between Macro &
Function
 I)In a macro call,the preprocessor
replaces the macro template with its
macro exapansion only.whereas, in a
functional call the control is passed to
a function along with certain
arguments,some calculations are
performed in the function& a useful
value is returned back from the
function.
 II) if we use a macro hundred times in
a program,the macro expansion goes
into our source code at hundred
different palaces,thus increasing the
program size. On the other hand,if a
function is used,then even if it is called
from hundred different places in the
program,it would take the same
amount of space in the program,thus
making the prigram smaller and
compact.
File Inclusion
 Used to include one file into another file
or it simply causes the entire content of
one file to be inserted into the source
code of another file.
 We use file inclusions for the following
reasons:
I) if we have a very large program, the
code is best divided into several different
files,each containing a set of related
functions.These files are then included at
the beginning of main program file.
II)There are some commonly needed
functions & macro definitions that can
be stored in a file &that file can be
included in every program we write
which would add all the statements in
this file to our program as if we have
typed in.
 The two ways to write include
statement:
#include “filename”
 #include “goto.h”: It searches for a file
named “goto.h” in the directory
containing the current file.
 #include<goto.h>: it searches for a file
named “goto.h” in a standard list of
system directories.
Undefining a Macro
 The #undef preprocessor directive is
used to undefine the constant or
macro defined by #define.
 Syntax:
 Example:
Preprocessor Operators
 The C preprocessor offers the
following operators to help create
macros −
I)The Macro Continuation () Operator
 A macro is normally confined to a
single line. The macro continuation
operator () is used to continue a
macro that is too long for a single line.
 For example −
II)The Stringize (#) Operator
 The stringize or number-sign operator
('#'), when used within a macro definition,
converts a macro parameter into a string
constant.
 This operator may be used only in a
macro having a specified argument or
parameter list.
 For example −
# define say(m) printf(#m)
void main()
{
clrscr(); Output:
say(Hello); Hello
getche();
}
III)The Token Pasting (##) Operator
 The token-pasting operator (##) within
a macro definition combines two
arguments.
 It permits two separate tokens in the
macro definition to be joined into a
single token.
 For example −
When the above code is compiled and executed, it
produces the following result −
It happened so because this example results in the
following actual output from the preprocessor −
Conditional Compilation
 These allow us to include certain
portion of the code depending upon
the output of constant expression.
 The #ifdef preprocessor directive
checks if macro is defined by #define.
If yes, it executes the code otherwise
#else code is executed, if present.
 Syntax:
Example:
#ifndef directive
 The #ifndef preprocessor directive
checks if macro is not defined by
#define.
 If yes, it executes the code otherwise
#else code is executed, if present.
 Syntax:
Example:
#pragma directive
 The #pragma preprocessor directive is
used to provide additional information
to the compiler.
 The #pragma directive is used by the
compiler to offer machine or
operating-system feature.
 Syntax:
Example:
 Syntax:
#pragma startup <function_name>
 startup pragma allow the program to specify function(s) that
should be called upon program startup
 Function is called before main().
 Syntax :
#pragma exit <function_name>
 exit pragma allow the program to specify function(s) that
should be called just before the program terminates through
_exit.
 Function is called after main().
 <function_name> must be a previously declared function
that takes no arguments and returns void.
 It should be declared as –
 void func(void);
 The function name must be defined (or declared) before the
pragma line is reached.
# error directive
 The #error preprocessor directive
indicates error.
 The compiler gives fatal error if #error
directive is found and skips further
compilation process.
Example:

More Related Content

What's hot (20)

Strings in C
Strings in CStrings in C
Strings in C
 
C functions
C functionsC functions
C functions
 
Preprocessors
Preprocessors Preprocessors
Preprocessors
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
String functions in C
String functions in CString functions in C
String functions in C
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Call by value
Call by valueCall by value
Call by value
 
pre processor directives in C
pre processor directives in Cpre processor directives in C
pre processor directives in C
 
Function in c
Function in cFunction in c
Function in c
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Function Pointer
Function PointerFunction Pointer
Function Pointer
 
C language ppt
C language pptC language ppt
C language ppt
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 

Similar to Preprocessor directives in c language

Similar to Preprocessor directives in c language (20)

C programming session6
C programming  session6C programming  session6
C programming session6
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro header
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
 
1 - Preprocessor.pptx
1 - Preprocessor.pptx1 - Preprocessor.pptx
1 - Preprocessor.pptx
 
Introduction to Preprocessors
Introduction to PreprocessorsIntroduction to Preprocessors
Introduction to Preprocessors
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Unit 5 quesn b ans5
Unit 5 quesn b ans5Unit 5 quesn b ans5
Unit 5 quesn b ans5
 
Inline functions & macros
Inline functions & macrosInline functions & macros
Inline functions & macros
 
ANSI C Macros
ANSI C MacrosANSI C Macros
ANSI C Macros
 
Chapter 13.1.11
Chapter 13.1.11Chapter 13.1.11
Chapter 13.1.11
 
Preprocessor.pptx
Preprocessor.pptxPreprocessor.pptx
Preprocessor.pptx
 
05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
Unit 5 Part 1 Macros
Unit 5 Part 1 MacrosUnit 5 Part 1 Macros
Unit 5 Part 1 Macros
 
Preprocesser in c++ by thanveer danish
Preprocesser in c++ by thanveer danishPreprocesser in c++ by thanveer danish
Preprocesser in c++ by thanveer danish
 

More from tanmaymodi4

Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1tanmaymodi4
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c languagetanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c languagetanmaymodi4
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c languagetanmaymodi4
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languagetanmaymodi4
 
Structures in c language
Structures in c languageStructures in c language
Structures in c languagetanmaymodi4
 
Union in c language
Union  in c languageUnion  in c language
Union in c languagetanmaymodi4
 

More from tanmaymodi4 (11)

Cryptocurrency
CryptocurrencyCryptocurrency
Cryptocurrency
 
Pointers in c v5 12102017 1
Pointers in c v5 12102017 1Pointers in c v5 12102017 1
Pointers in c v5 12102017 1
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c language
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Union in c language
Union  in c languageUnion  in c language
Union in c language
 

Recently uploaded

Cooling Tower SERD pH drop issue (11 April 2024) .pptx
Cooling Tower SERD pH drop issue (11 April 2024) .pptxCooling Tower SERD pH drop issue (11 April 2024) .pptx
Cooling Tower SERD pH drop issue (11 April 2024) .pptxmamansuratman0253
 
Turn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxTurn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxStephen Sitton
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
Malware Detection By Machine Learning Presentation.pptx
Malware Detection By Machine Learning  Presentation.pptxMalware Detection By Machine Learning  Presentation.pptx
Malware Detection By Machine Learning Presentation.pptxalishapatidar2021
 
Risk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectRisk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectErbil Polytechnic University
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Coursebim.edu.pl
 
OOP concepts -in-Python programming language
OOP concepts -in-Python programming languageOOP concepts -in-Python programming language
OOP concepts -in-Python programming languageSmritiSharma901052
 
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmComputer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmDeepika Walanjkar
 
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSHigh Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSsandhya757531
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodManicka Mamallan Andavar
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfManish Kumar
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdfCaalaaAbdulkerim
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solidnamansinghjarodiya
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingBootNeck1
 
Internship PPT ukai thermal power station .pptx
Internship PPT ukai thermal power station .pptxInternship PPT ukai thermal power station .pptx
Internship PPT ukai thermal power station .pptxmalikavita731
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfDrew Moseley
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 

Recently uploaded (20)

Cooling Tower SERD pH drop issue (11 April 2024) .pptx
Cooling Tower SERD pH drop issue (11 April 2024) .pptxCooling Tower SERD pH drop issue (11 April 2024) .pptx
Cooling Tower SERD pH drop issue (11 April 2024) .pptx
 
Turn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptxTurn leadership mistakes into a better future.pptx
Turn leadership mistakes into a better future.pptx
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
Malware Detection By Machine Learning Presentation.pptx
Malware Detection By Machine Learning  Presentation.pptxMalware Detection By Machine Learning  Presentation.pptx
Malware Detection By Machine Learning Presentation.pptx
 
Risk Management in Engineering Construction Project
Risk Management in Engineering Construction ProjectRisk Management in Engineering Construction Project
Risk Management in Engineering Construction Project
 
Katarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School CourseKatarzyna Lipka-Sidor - BIM School Course
Katarzyna Lipka-Sidor - BIM School Course
 
OOP concepts -in-Python programming language
OOP concepts -in-Python programming languageOOP concepts -in-Python programming language
OOP concepts -in-Python programming language
 
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmComputer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
 
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMSHigh Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
High Voltage Engineering- OVER VOLTAGES IN ELECTRICAL POWER SYSTEMS
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument method
 
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdfModule-1-(Building Acoustics) Noise Control (Unit-3). pdf
Module-1-(Building Acoustics) Noise Control (Unit-3). pdf
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Research Methodology for Engineering pdf
Research Methodology for Engineering pdfResearch Methodology for Engineering pdf
Research Methodology for Engineering pdf
 
Engineering Drawing section of solid
Engineering Drawing     section of solidEngineering Drawing     section of solid
Engineering Drawing section of solid
 
System Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event SchedulingSystem Simulation and Modelling with types and Event Scheduling
System Simulation and Modelling with types and Event Scheduling
 
Internship PPT ukai thermal power station .pptx
Internship PPT ukai thermal power station .pptxInternship PPT ukai thermal power station .pptx
Internship PPT ukai thermal power station .pptx
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdf
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 

Preprocessor directives in c language

  • 2. Definition  A preprocessor is a program that processes our source program before it is passed to the compiler.  The preprocessor works on the source code and creates “expanded source code”.  The preprocessor offers several features called preprocessor directives.  Each of theses preprocessor directives begin with a # symbol.  The directives can be placed anywhere in a program but most often placed at the beginning of the program,before the function definition.
  • 3. Preprocessor directives are executed before compilation.
  • 4.  The various preprocessor directives are as follows: 1)Macro Expansion (#define) II)File Inclusion(#include) III)Conditional Compilation(#ifdef -#endif) IV)Miscellaneous Directives (#undef,#pragma-startup,exit,warn)
  • 5. Macro Expansion  A “macro” is a fragment of code which has been given a name.  Wherever the name is used,it is replaced by the contents of the macro.  There are two kinds of macros which are as follows: I)Object-like macros resemble data objects II)Function-like macros resemble function calls.
  • 6. Object –like Macros  The object-like macro is an identifier that is replaced by value.  It is widely used to represent numeric constants.  It is called object-like because it looks like a data object in code that uses it.  Syntax: #define identifier replacement-text
  • 7. Examples #define x 4 x=identifier 4=replacement-text void main() { int a; a=x; } #define pi 3.14 pi=identifier 3.14=substitute void main() { float r=6.25,area; area=pi*r*r; printf(“Area of circle=%f”,area); }
  • 8. Note:  To create macros with the #define directive,the syntax for macros is: #define macro macro expansion replacement list  #define directive can be used as follows: I) It can be used to define operators like: #define AND && #define OR ||
  • 9. II)it could be used even to replace a condition: # define AND && #define ARRANGE (a>25 AND a<50) III) It could be used to replace even an entire C statement like: # define FOUND printf(“Hello World”)
  • 10. Function-like Macro  It looks like a function call & can be defined with the # define directive but with a pair of braces or parenthesis immediately after the macro name.  For Example: #define Area(x) 3.14* r*r
  • 11. Macro with arguments  Function –like macros can take arguments just like true functions.
  • 12. Difference between Macro & Function  I)In a macro call,the preprocessor replaces the macro template with its macro exapansion only.whereas, in a functional call the control is passed to a function along with certain arguments,some calculations are performed in the function& a useful value is returned back from the function.
  • 13.  II) if we use a macro hundred times in a program,the macro expansion goes into our source code at hundred different palaces,thus increasing the program size. On the other hand,if a function is used,then even if it is called from hundred different places in the program,it would take the same amount of space in the program,thus making the prigram smaller and compact.
  • 14. File Inclusion  Used to include one file into another file or it simply causes the entire content of one file to be inserted into the source code of another file.  We use file inclusions for the following reasons: I) if we have a very large program, the code is best divided into several different files,each containing a set of related functions.These files are then included at the beginning of main program file.
  • 15. II)There are some commonly needed functions & macro definitions that can be stored in a file &that file can be included in every program we write which would add all the statements in this file to our program as if we have typed in.  The two ways to write include statement: #include “filename”
  • 16.  #include “goto.h”: It searches for a file named “goto.h” in the directory containing the current file.  #include<goto.h>: it searches for a file named “goto.h” in a standard list of system directories.
  • 17. Undefining a Macro  The #undef preprocessor directive is used to undefine the constant or macro defined by #define.  Syntax:  Example:
  • 18. Preprocessor Operators  The C preprocessor offers the following operators to help create macros − I)The Macro Continuation () Operator  A macro is normally confined to a single line. The macro continuation operator () is used to continue a macro that is too long for a single line.  For example −
  • 19. II)The Stringize (#) Operator  The stringize or number-sign operator ('#'), when used within a macro definition, converts a macro parameter into a string constant.  This operator may be used only in a macro having a specified argument or parameter list.  For example − # define say(m) printf(#m) void main() { clrscr(); Output: say(Hello); Hello getche(); }
  • 20. III)The Token Pasting (##) Operator  The token-pasting operator (##) within a macro definition combines two arguments.  It permits two separate tokens in the macro definition to be joined into a single token.  For example −
  • 21. When the above code is compiled and executed, it produces the following result − It happened so because this example results in the following actual output from the preprocessor −
  • 22. Conditional Compilation  These allow us to include certain portion of the code depending upon the output of constant expression.  The #ifdef preprocessor directive checks if macro is defined by #define. If yes, it executes the code otherwise #else code is executed, if present.  Syntax:
  • 24. #ifndef directive  The #ifndef preprocessor directive checks if macro is not defined by #define.  If yes, it executes the code otherwise #else code is executed, if present.  Syntax:
  • 26. #pragma directive  The #pragma preprocessor directive is used to provide additional information to the compiler.  The #pragma directive is used by the compiler to offer machine or operating-system feature.  Syntax:
  • 28.  Syntax: #pragma startup <function_name>  startup pragma allow the program to specify function(s) that should be called upon program startup  Function is called before main().  Syntax : #pragma exit <function_name>  exit pragma allow the program to specify function(s) that should be called just before the program terminates through _exit.  Function is called after main().  <function_name> must be a previously declared function that takes no arguments and returns void.  It should be declared as –  void func(void);  The function name must be defined (or declared) before the pragma line is reached.
  • 29. # error directive  The #error preprocessor directive indicates error.  The compiler gives fatal error if #error directive is found and skips further compilation process.