SlideShare a Scribd company logo
PRE-PROCESSOR DIRECTIVES IN C
BY
JOHN JOSE
INTRODUCTION
• One of the unique feature of C language is
preprocessor.
• The pre processor is a program that processes the
source code before it passes through compiler
• Preprocessor directives are divided into three
categories,
1.Macro substitution directives
2.file inclusion directives
3.compiler control directives
Macro Substitution:
• Macro substitution is a process where an identifier
in a program replaced by predefined string
composed of one or more tokens
• It is achieved by #define directives
Examples
• #define PI 3.142
• #define TRUE 1
• #define AND &&
• #define LESSTHAN <
• #define MESSAGE "welcome to C"
Example(program by programmer)
#include<stdio.h>
#define LESSTHAN <
int main()
{
int a = 30;
if(a LESSTHAN 40)
printf("a is Smaller");
return(0);
}
Program is processed by pre-processor
int main()
{
int a = 30;
if(a < 40)
printf("a is Smaller");
return(0); }
Program is processed by compiler
a is Smaller
FILE INCLUSSION
• An external file containing functions or macro
definition can be included as a part of program so
that we need not rewrite those function or macro
definition.
• This is achieved by #include directives
Example
• Step1 : Type this Code
• In this Code write only function definition as you
write in General C Program
int add(int a,int b)
{
return(a+b);
}
Step 2
• Save Above Code with [.h ] Extension .
• Let name of our header file be myhead [ myhead.h ]
• Compile Code if required.
Step 3 : Write Main Program
#include<stdio.h>
#include"myhead.h"
void main()
{
int number1=10,number2=10,number3;
number3 = add(number1,number2);
printf("Addition of Two numbers : %d",number3);
}
• Include Our New Header File .
• Instead of writing < myhead.h> use this
terminology “myhead.h”
• All the Functions defined in the myhead.h header file are
now ready for use .
• Directly call function add(); [ Provide proper parameter
and take care of return type ]
Note
While running your program precaution to be taken :
Both files [ myhead.h and sample.c ] should be in same
folder.
ADDITIONAL PREPROCESSOR DIRECTIVES
• #ELIF DIRECTIVE: #ELIF Enable us to establish an if
else sequence for testing multiple conditions.
• #PRAGMA DIRECTIVES: #PRAGMA Is an
implementation oriented directive that allow us to
specify various instruction to be given to compiler
Syntax: #pragma name
• #ERROR : #ERROR Directive is used to produce
diagonastic messages during debugging
• Syntax :#ERROR error message.
PREPROCESSOR OPERATORS
• There are two preprocessor operators namely,
• 1. Stringizing operator (#): it is used in
definition of macro functions. This operators
allows a formal argument within macro
definition to be converted to string
• Syntax: # define sum(xy)
printf(#xy”=%f/n”,xy);
2.TOKEN PASTING OPERATORS
The token pasting operator enables us to
combine two within a macro definition to
form a single token
Syntax : #define
combine(string1,string2)s1##s2

More Related Content

What's hot

Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Rokonuzzaman Rony
 
C fundamental
C fundamentalC fundamental
C fundamental
Selvam Edwin
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
arnold 7490
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
Learn By Watch
 
File handling in c
File handling in cFile handling in c
File handling in c
aakanksha s
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
Nilesh Dalvi
 
Python reading and writing files
Python reading and writing filesPython reading and writing files
Python reading and writing files
Mukesh Tekwani
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in python
TMARAGATHAM
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
Koganti Ravikumar
 
Break and continue
Break and continueBreak and continue
Break and continue
Frijo Francis
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
ForwardBlog Enewzletter
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
Kamal Acharya
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
Abhishek Choksi
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
TIB Academy
 
Unix notes
Unix notesUnix notes
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
Hossain Md Shakhawat
 
Datatypes in c
Datatypes in cDatatypes in c
Pre processor directives in c
Pre processor directives in cPre processor directives in c
C Language
C LanguageC Language
C Language
Aakash Singh
 

What's hot (20)

Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
Python reading and writing files
Python reading and writing filesPython reading and writing files
Python reading and writing files
 
Exception handling and function in python
Exception handling and function in pythonException handling and function in python
Exception handling and function in python
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Constructors & destructors
Constructors & destructorsConstructors & destructors
Constructors & destructors
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
 
Unix notes
Unix notesUnix notes
Unix notes
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Decision making and looping
Decision making and loopingDecision making and looping
Decision making and looping
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
 
C Language
C LanguageC Language
C Language
 

Similar to Preprocessor

Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
TejaswiB4
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro header
hasan Mohammad
 
5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.
Fiaz Hussain
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
valerie5142000
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
LakshyaChauhan21
 
Basic Structure of C Language and Related Term
Basic Structure of C Language  and Related TermBasic Structure of C Language  and Related Term
Basic Structure of C Language and Related Term
MuhammadWaseem305
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
rabbianasir99
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
TechNGyan
 
Unit 5
Unit 5Unit 5
Unit 5
rohassanie
 
ANSI C Macros
ANSI C MacrosANSI C Macros
ANSI C Macros
Srikrishnan Suresh
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
CoolGamer16
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
tanmaymodi4
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
Tanmay Modi
 
C structure
C structureC structure
C structure
ankush9927
 
Preprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryPreprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP Library
Meghaj Mallick
 
introduction of c langauge(I unit)
introduction of c langauge(I unit)introduction of c langauge(I unit)
introduction of c langauge(I unit)
Prashant Sharma
 
Cpa lecture (theory) 01_
Cpa lecture (theory) 01_Cpa lecture (theory) 01_
C++ basics
C++ basicsC++ basics
C++ basics
AllsoftSolutions
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
Abdullah Jan
 

Similar to Preprocessor (20)

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
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro header
 
5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.5.Hello World program Explanation. ||C Programming tutorial.
5.Hello World program Explanation. ||C Programming tutorial.
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
C++ Constructs.pptx
C++ Constructs.pptxC++ Constructs.pptx
C++ Constructs.pptx
 
Basic Structure of C Language and Related Term
Basic Structure of C Language  and Related TermBasic Structure of C Language  and Related Term
Basic Structure of C Language and Related Term
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Unit 5
Unit 5Unit 5
Unit 5
 
ANSI C Macros
ANSI C MacrosANSI C Macros
ANSI C Macros
 
Basics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptxBasics of C Lecture 2[16097].pptx
Basics of C Lecture 2[16097].pptx
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c language
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
C structure
C structureC structure
C structure
 
Preprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryPreprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP Library
 
introduction of c langauge(I unit)
introduction of c langauge(I unit)introduction of c langauge(I unit)
introduction of c langauge(I unit)
 
Cpa lecture (theory) 01_
Cpa lecture (theory) 01_Cpa lecture (theory) 01_
Cpa lecture (theory) 01_
 
C++ basics
C++ basicsC++ basics
C++ basics
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 

More from baabtra.com - No. 1 supplier of quality freshers

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
baabtra.com - No. 1 supplier of quality freshers
 
Best coding practices
Best coding practicesBest coding practices
Core java - baabtra
Core java - baabtraCore java - baabtra
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
baabtra.com - No. 1 supplier of quality freshers
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
baabtra.com - No. 1 supplier of quality freshers
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
baabtra.com - No. 1 supplier of quality freshers
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php database connectivity
Php database connectivityPhp database connectivity
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
baabtra.com - No. 1 supplier of quality freshers
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Blue brain
Blue brainBlue brain
5g
5g5g
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Gd baabtra
Gd baabtraGd baabtra

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Preprocessor

  • 1.
  • 3. INTRODUCTION • One of the unique feature of C language is preprocessor. • The pre processor is a program that processes the source code before it passes through compiler • Preprocessor directives are divided into three categories, 1.Macro substitution directives 2.file inclusion directives 3.compiler control directives
  • 4. Macro Substitution: • Macro substitution is a process where an identifier in a program replaced by predefined string composed of one or more tokens • It is achieved by #define directives
  • 5. Examples • #define PI 3.142 • #define TRUE 1 • #define AND && • #define LESSTHAN < • #define MESSAGE "welcome to C"
  • 6. Example(program by programmer) #include<stdio.h> #define LESSTHAN < int main() { int a = 30; if(a LESSTHAN 40) printf("a is Smaller"); return(0); }
  • 7. Program is processed by pre-processor int main() { int a = 30; if(a < 40) printf("a is Smaller"); return(0); } Program is processed by compiler a is Smaller
  • 8. FILE INCLUSSION • An external file containing functions or macro definition can be included as a part of program so that we need not rewrite those function or macro definition. • This is achieved by #include directives
  • 9. Example • Step1 : Type this Code • In this Code write only function definition as you write in General C Program int add(int a,int b) { return(a+b); }
  • 10. Step 2 • Save Above Code with [.h ] Extension . • Let name of our header file be myhead [ myhead.h ] • Compile Code if required.
  • 11. Step 3 : Write Main Program #include<stdio.h> #include"myhead.h" void main() { int number1=10,number2=10,number3; number3 = add(number1,number2); printf("Addition of Two numbers : %d",number3); }
  • 12. • Include Our New Header File . • Instead of writing < myhead.h> use this terminology “myhead.h” • All the Functions defined in the myhead.h header file are now ready for use . • Directly call function add(); [ Provide proper parameter and take care of return type ] Note While running your program precaution to be taken : Both files [ myhead.h and sample.c ] should be in same folder.
  • 13. ADDITIONAL PREPROCESSOR DIRECTIVES • #ELIF DIRECTIVE: #ELIF Enable us to establish an if else sequence for testing multiple conditions. • #PRAGMA DIRECTIVES: #PRAGMA Is an implementation oriented directive that allow us to specify various instruction to be given to compiler Syntax: #pragma name • #ERROR : #ERROR Directive is used to produce diagonastic messages during debugging • Syntax :#ERROR error message.
  • 14. PREPROCESSOR OPERATORS • There are two preprocessor operators namely, • 1. Stringizing operator (#): it is used in definition of macro functions. This operators allows a formal argument within macro definition to be converted to string • Syntax: # define sum(xy) printf(#xy”=%f/n”,xy);
  • 15. 2.TOKEN PASTING OPERATORS The token pasting operator enables us to combine two within a macro definition to form a single token Syntax : #define combine(string1,string2)s1##s2