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?

1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
Harish Kumawat
 

Was ist angesagt? (20)

12. Case Tools
12. Case Tools12. Case Tools
12. Case Tools
 
The Loops
The LoopsThe Loops
The Loops
 
Algorithm and Programming (Sequential Structure)
Algorithm and Programming (Sequential Structure)Algorithm and Programming (Sequential Structure)
Algorithm and Programming (Sequential Structure)
 
1. over view and history of c
1. over view and history of c1. over view and history of c
1. over view and history of c
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Data types
Data typesData types
Data types
 
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
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
programming and languages (chapter 14)
programming and languages (chapter 14)programming and languages (chapter 14)
programming and languages (chapter 14)
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in c
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
SDLC
SDLCSDLC
SDLC
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Translators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreterTranslators(Compiler, Assembler) and interpreter
Translators(Compiler, Assembler) and interpreter
 
VIM for (PHP) Programmers
VIM for (PHP) ProgrammersVIM for (PHP) Programmers
VIM for (PHP) Programmers
 
Software engineering project management
Software engineering project managementSoftware engineering project management
Software engineering project management
 
High level and Low level Language
High level and Low level Language High level and Low level Language
High level and Low level Language
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
 
Introduction to cython
Introduction to cythonIntroduction to cython
Introduction to cython
 

Ähnlich wie Preprocessor

Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
TechNGyan
 
1st presentation.pptxajshfjkashfnajsfbasjk
1st presentation.pptxajshfjkashfnajsfbasjk1st presentation.pptxajshfjkashfnajsfbasjk
1st presentation.pptxajshfjkashfnajsfbasjk
mahnoor01999
 

Ähnlich wie Preprocessor (20)

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
 
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
 
1st presentation.pptxajshfjkashfnajsfbasjk
1st presentation.pptxajshfjkashfnajsfbasjk1st presentation.pptxajshfjkashfnajsfbasjk
1st presentation.pptxajshfjkashfnajsfbasjk
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 

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