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

Weitere ähnliche Inhalte

Was ist angesagt?

Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageDr.YNM
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While LoopAbhishek Choksi
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in pythonTMARAGATHAM
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorialMohit Saini
 
Applications of queues ii
Applications of queues   iiApplications of queues   ii
Applications of queues iiTech_MX
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Functions in python
Functions in pythonFunctions in python
Functions in pythoncolorsof
 
Basics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest WayBasics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest Wayakshay rajpure
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
Computer System Overview Class XI CS
Computer System Overview Class XI CSComputer System Overview Class XI CS
Computer System Overview Class XI CSclass12sci
 

Was ist angesagt? (20)

Loops in c
Loops in cLoops in c
Loops in c
 
File operations
File operationsFile operations
File operations
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
C programming tutorial
C programming tutorialC programming tutorial
C programming tutorial
 
File operations in c
File operations in cFile operations in c
File operations in c
 
Applications of queues ii
Applications of queues   iiApplications of queues   ii
Applications of queues ii
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Basics of c++
Basics of c++Basics of c++
Basics of c++
 
Basics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest WayBasics Of C Programming For Beginners In Easiest Way
Basics Of C Programming For Beginners In Easiest Way
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Dictionaries in Python
Dictionaries in PythonDictionaries in Python
Dictionaries in Python
 
Computer System Overview Class XI CS
Computer System Overview Class XI CSComputer System Overview Class XI CS
Computer System Overview Class XI CS
 
Types of system software
Types of system softwareTypes of system software
Types of system software
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
The Loops
The LoopsThe Loops
The Loops
 

Ähnlich wie Preprocessor

Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
6 preprocessor macro header
6 preprocessor macro header6 preprocessor macro header
6 preprocessor macro headerhasan 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
 
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 TermMuhammadWaseem305
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesrabbianasir99
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg PatelTechNGyan
 
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].pptxCoolGamer16
 
Preprocessor directives in c language
Preprocessor directives in c languagePreprocessor directives in c language
Preprocessor directives in c languagetanmaymodi4
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguageTanmay Modi
 
Preprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryPreprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryMeghaj 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
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ toolAbdullah Jan
 

Ähnlich wie 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
 

Mehr von baabtra.com - No. 1 supplier of quality freshers

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