SlideShare ist ein Scribd-Unternehmen logo
1 von 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:

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
 
Functions in C
Functions in CFunctions in C
Functions in C
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Strings in C
Strings in CStrings in C
Strings in C
 
Function in C
Function in CFunction in C
Function in C
 
Inline function
Inline functionInline function
Inline function
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 

Ähnlich wie Preprocessor directives in c language

Ähnlich wie 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
 
Introduction To C++ programming and its basic concepts
Introduction To C++ programming and its basic conceptsIntroduction To C++ programming and its basic concepts
Introduction To C++ programming and its basic concepts
 
Preprocessors
Preprocessors Preprocessors
Preprocessors
 
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
 

Mehr von 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
 
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
 

Mehr von tanmaymodi4 (10)

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
 
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
 

Kürzlich hochgeladen

(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 

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.