SlideShare a Scribd company logo
3
Most read
12
Most read
14
Most read
C             Programming
                       Language
               By:
    Yogendra Pal
yogendra@learnbywatch.com
  Dedicated to My Mother and Father
Keep your notebook with you.

Write important point and questions that comes in your mind

     Solve Mind band exercise.
                                     Rewind when not clear


              Ask Questions by call or SMS or by mail


Keep Watching Keep Learning

THIS IS PREPROCESSOR
Preprocessor
• Preprocessor processes source program before
  it is passed to compiler.

         preprocessor    Compiler


• Produce a source code file with the
  preprocessing commands properly sorted out.
Preprocessor Directives
• Preprocessor commands are known as
  directives.
• Preprocessor provides certain features.
• These features are also known as preprocessor
  directives.
• Preprocessor directives start with # sign.
        #include <stdio.h>
Preprocessor Directives...
• Preprocessor directives can be placed any
  where in the source program.
• Note: Place it at start of the program.
• Each preprocessor directive must be on it’s
  own line.
#include <stdio.h>   #include <stdio.h> #include <conio.h>
#include <conio.h>
Preprocessor Directives
•   Macro Expansion
•   File Inclusion
•   Conditional compilation
•   Miscellaneous directives
Macro Expansion
• #define directive is known as macro expansion.
• Definition:
         #define PI 3.1415
• General Form:
  – #define macro_template macro_expansion
  – #define macro_name char_sequence
Macro Expansion...
• Preprocessor search for macro definition.
• After finding #define directive it search entire
  program for macro_template.
• Replace     each     macro_template        with
  macro_expansion.
• Best Practice: Use capital letters for macro
  template.
• Do not use semicolon ‘ ; ’
Macros, Why?
• To write efficient programs.
• To increase readiabiality of programs.
• Variable vs macro_template
  – Compiler can generate faster and compact code for
    constant than it can for variables.
  – When you are dealing with a constant, why use
    variable.
  – A variable may change in the program.
Macros, Where?
• Replace operator:
      #define AND &&
      #define OR ||

• Replace condition:
      #define EXCELLENT (a>=75)
• Replace statement:
     #define ALERT printf(“Security Alert”);
Macros...
• Defined macro name can be used as a part of
  definition of other macro name.
         #define MIN 1
         #define MAX 9
         #define MIDDLE (MAX-MIN)/2

• No text substitution occur if the identifier is
  within a quoted string.
Macros with Arguments
• Macros can have arguments, same as functions
     #define ISEXCELLENT(x) (x >= 75)
     #define ISLOWER(x) (x>=97 && x<=122)

• Note: Space between Macro and it’s arguments.
           ISLOWER(x)     ISLOWER (x)
Macros with Arguments...
• Macros expansions should be enclosed within
  paranthesis.
       #define ISLOWER(x) (x>=97 && x<=122)
       if(!ISLOWER(‘a’));

• Use ‘’ to split macro in multiple line.
       #define HLINE for(i=0; i < 40; i++)
                      printf(“_”);
Macros vs Functions
           MACROS                       FUNCTIONS
Just the replacement of the   Passing arguments, doing
code.                         calculation, returning results.
                              (More serious work).
Macros make the program run   Function calls and return make
faster.                       the program slow.
Increase the program size     Make program smaller and
                              compact.
File Inclusion
• causes one file to be included in another.
       #include <filename> //OR
       #include “filename”
• <filename> : search the directory on current
  directory only.
• “filename” : search the directory on current
  directory and specified directories as specified
  in the include search path.
Why File Inclusion?
• Divide a program in multiple files.
  – Each file contains related functions.
• Some functions or macros are required in each
  program
  – Put them in a file (Library).
  – Include them in program that need them.
• Nested includes: Included file may have more
  included files in it.
Conditional Compilation
• Write single program to run on different
  environments.
  – #ifdef – if defined
  – #endif – end if
  – #else – else
  – #ifndef – in not defined
  – #if – if
  – #elif – else if
#ifdef & #endif
• General form:
      #ifdef macroname
              statement sequence
      #endif

• if macroname has been defined using #define
  the code between #ifdef & #endif will execute.
#else
• Use #else with #ifdef same as else with if.
• General-form:
        #ifdef macroname
                statement sequence
        #else
                statement sequence
        #endif
#ifndef
• #ifndef is just opposite to #ifdef.
       #ifndef __file_h
               #define __file_h

• #if directive test whether an expression
  evaluates to nonzero value or not.
• #elif used same as else if.
Where conditional compilation?
  • Instead of comments.
      – Nested comments not allowed in C.
/*                                        #ifdef BLOCK
for(i =0; i<=students;i++)                for(i =0; i<=students;i++)
            count++; /*total students*/               count++; /*total students*/
printf(“%d”,count);                       printf(“%d”,count);
*/                                        #endif
Where conditional compilation?
• Run the same code on different environment.
       #ifdef WINDOWS
               statement sequence
       #else
               statemet sequence
       #endif
Where conditional compilation?
• To avoide multiple declaration error.


                   #                 #
                        <                 <

                   >                 >
                                     #
                                          <

                                     >
To get complete benefit of this tutorial solve all the quiz on
                 www.learnbywatch.com

        For any problem in this tutorial mail me at
              yogendra@learnbywatch.com
                  with the subject “C”

               For Other information mail at
                 info@learnbywatch.com

More Related Content

What's hot (20)

PPTX
C Programming: Control Structure
Sokngim Sa
 
PPT
Operator Overloading
Nilesh Dalvi
 
PPTX
Presentation on Function in C Programming
Shuvongkor Barman
 
PPTX
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
PPTX
Functions in c language
tanmaymodi4
 
PPTX
Functions in C
Kamal Acharya
 
PPT
Class and object in C++
rprajat007
 
PDF
Function overloading ppt
Prof. Dr. K. Adisesha
 
PPTX
C functions
University of Potsdam
 
PPTX
Static Data Members and Member Functions
MOHIT AGARWAL
 
PPTX
Presentation on C Switch Case Statements
Dipesh Panday
 
PDF
Arrays in Java
Naz Abdalla
 
PPTX
Inheritance in c++
Vineeta Garg
 
PPTX
User defined functions in C
Harendra Singh
 
PPTX
Function in C program
Nurul Zakiah Zamri Tan
 
PPTX
classes and objects in C++
HalaiHansaika
 
PPTX
Looping statements in C
Jeya Lakshmi
 
PPT
File handling in c
David Livingston J
 
PPT
user defined function
King Kavin Patel
 
PPTX
Programming in c Arrays
janani thirupathi
 
C Programming: Control Structure
Sokngim Sa
 
Operator Overloading
Nilesh Dalvi
 
Presentation on Function in C Programming
Shuvongkor Barman
 
Pointers in C Programming
Jasleen Kaur (Chandigarh University)
 
Functions in c language
tanmaymodi4
 
Functions in C
Kamal Acharya
 
Class and object in C++
rprajat007
 
Function overloading ppt
Prof. Dr. K. Adisesha
 
Static Data Members and Member Functions
MOHIT AGARWAL
 
Presentation on C Switch Case Statements
Dipesh Panday
 
Arrays in Java
Naz Abdalla
 
Inheritance in c++
Vineeta Garg
 
User defined functions in C
Harendra Singh
 
Function in C program
Nurul Zakiah Zamri Tan
 
classes and objects in C++
HalaiHansaika
 
Looping statements in C
Jeya Lakshmi
 
File handling in c
David Livingston J
 
user defined function
King Kavin Patel
 
Programming in c Arrays
janani thirupathi
 

Viewers also liked (20)

PPT
pre processor directives in C
Sahithi Naraparaju
 
PPT
Preprocessor in C
Prabhu Govind
 
PPT
Preprocessors
Gourav Arora
 
PDF
Module 05 Preprocessor and Macros in C
Tushar B Kute
 
PDF
The C Preprocessor
iuui
 
PPTX
Pre processor directives in c
baabtra.com - No. 1 supplier of quality freshers
 
PPT
Macro
Google
 
PPTX
System Programming Unit II
Manoj Patil
 
PPT
C++ Preprocessor Directives
Wasif Altaf
 
PPT
Web Project Presentation - JoinPakForces
Wasif Altaf
 
PPT
Compiler
IGZ Software house
 
PDF
Implementation of c string functions
mohamed sikander
 
PPTX
What is c
Nitesh Saitwal
 
PPTX
Embedded C workshop
Mostafa El-koumy
 
PPTX
C string
University of Potsdam
 
PPTX
C programming - String
Achyut Devkota
 
DOC
String in c
Suneel Dogra
 
PPT
Assembler
Mohd Arif
 
PDF
Lecture 01 introduction to compiler
Iffat Anjum
 
PDF
Embedded C - Lecture 2
Mohamed Abdallah
 
pre processor directives in C
Sahithi Naraparaju
 
Preprocessor in C
Prabhu Govind
 
Preprocessors
Gourav Arora
 
Module 05 Preprocessor and Macros in C
Tushar B Kute
 
The C Preprocessor
iuui
 
Macro
Google
 
System Programming Unit II
Manoj Patil
 
C++ Preprocessor Directives
Wasif Altaf
 
Web Project Presentation - JoinPakForces
Wasif Altaf
 
Implementation of c string functions
mohamed sikander
 
What is c
Nitesh Saitwal
 
Embedded C workshop
Mostafa El-koumy
 
C programming - String
Achyut Devkota
 
String in c
Suneel Dogra
 
Assembler
Mohd Arif
 
Lecture 01 introduction to compiler
Iffat Anjum
 
Embedded C - Lecture 2
Mohamed Abdallah
 
Ad

Similar to Preprocessor (20)

PPTX
UNIT 4A-preprocessor.pptx for c language and basic knowledge
2024163103shubham
 
PPT
Preprocessors
Koganti Ravikumar
 
PDF
05 -working_with_the_preproce
Hector Garzo
 
PPTX
Preprocessor directives in c laguage
Tanmay Modi
 
PDF
6 preprocessor macro header
hasan Mohammad
 
PPT
PreProcessorDirective.ppt
Osmania University
 
PPTX
Preprocessor
lalithambiga kamaraj
 
PPTX
1 - Preprocessor.pptx
AlAmos4
 
PPTX
Unit-IV.pptx
Mehul Desai
 
PPTX
Programming Fundamentals lecture 5
REHAN IJAZ
 
PDF
Unit 5 quesn b ans5
Sowri Rajan
 
PDF
3 1. preprocessor, math, stdlib
웅식 전
 
PPT
Lecture 21 - Preprocessor and Header File
Md. Imran Hossain Showrov
 
PDF
ANSI C Macros
Srikrishnan Suresh
 
PDF
0100_Embeded_C_CompilationProcess.pdf
KhaledIbrahim10923
 
PPTX
c programming session 1.pptx
RSathyaPriyaCSEKIOT
 
PPT
c-programming
Zulhazmi Harith
 
PPTX
CSE240 Macros and Preprocessing
Garrett Gutierrez
 
UNIT 4A-preprocessor.pptx for c language and basic knowledge
2024163103shubham
 
Preprocessors
Koganti Ravikumar
 
05 -working_with_the_preproce
Hector Garzo
 
Preprocessor directives in c laguage
Tanmay Modi
 
6 preprocessor macro header
hasan Mohammad
 
PreProcessorDirective.ppt
Osmania University
 
Preprocessor
lalithambiga kamaraj
 
1 - Preprocessor.pptx
AlAmos4
 
Unit-IV.pptx
Mehul Desai
 
Programming Fundamentals lecture 5
REHAN IJAZ
 
Unit 5 quesn b ans5
Sowri Rajan
 
3 1. preprocessor, math, stdlib
웅식 전
 
Lecture 21 - Preprocessor and Header File
Md. Imran Hossain Showrov
 
ANSI C Macros
Srikrishnan Suresh
 
0100_Embeded_C_CompilationProcess.pdf
KhaledIbrahim10923
 
c programming session 1.pptx
RSathyaPriyaCSEKIOT
 
c-programming
Zulhazmi Harith
 
CSE240 Macros and Preprocessing
Garrett Gutierrez
 
Ad

More from Learn By Watch (20)

PPTX
Tutorial 9 fm
Learn By Watch
 
PPTX
Phase modulation
Learn By Watch
 
PPTX
Demodulation of fm pll detector
Learn By Watch
 
PPTX
Demodulation of fm slope and balanced slope detector
Learn By Watch
 
PPTX
In direct method of fm generation armstrong method
Learn By Watch
 
PPTX
Direct method of fm generation hartley oscillator method
Learn By Watch
 
PPTX
Carson's rule
Learn By Watch
 
PPTX
Spectrum and power of wbfm
Learn By Watch
 
PPTX
Narrow band frequency modulation nbfm
Learn By Watch
 
PPTX
General expression of fm signal
Learn By Watch
 
PPTX
Angle modulation
Learn By Watch
 
PPTX
Frequency division multiplexing
Learn By Watch
 
PPTX
Vsb modulation
Learn By Watch
 
PPTX
Demodulation of ssb synchronous detector
Learn By Watch
 
PPTX
Generarion of ssb phase discrimination method
Learn By Watch
 
PPTX
Generarion of ssb frequency discrimination method
Learn By Watch
 
PPTX
Ssb modulation
Learn By Watch
 
PPTX
Demodulation of dsb sc costas receiver
Learn By Watch
 
PPTX
Quadrature carrier multiplexing qam
Learn By Watch
 
PPTX
Demodulation of am synchronous detector
Learn By Watch
 
Tutorial 9 fm
Learn By Watch
 
Phase modulation
Learn By Watch
 
Demodulation of fm pll detector
Learn By Watch
 
Demodulation of fm slope and balanced slope detector
Learn By Watch
 
In direct method of fm generation armstrong method
Learn By Watch
 
Direct method of fm generation hartley oscillator method
Learn By Watch
 
Carson's rule
Learn By Watch
 
Spectrum and power of wbfm
Learn By Watch
 
Narrow band frequency modulation nbfm
Learn By Watch
 
General expression of fm signal
Learn By Watch
 
Angle modulation
Learn By Watch
 
Frequency division multiplexing
Learn By Watch
 
Vsb modulation
Learn By Watch
 
Demodulation of ssb synchronous detector
Learn By Watch
 
Generarion of ssb phase discrimination method
Learn By Watch
 
Generarion of ssb frequency discrimination method
Learn By Watch
 
Ssb modulation
Learn By Watch
 
Demodulation of dsb sc costas receiver
Learn By Watch
 
Quadrature carrier multiplexing qam
Learn By Watch
 
Demodulation of am synchronous detector
Learn By Watch
 

Preprocessor

  • 1. C Programming Language By: Yogendra Pal [email protected] Dedicated to My Mother and Father
  • 2. Keep your notebook with you. Write important point and questions that comes in your mind Solve Mind band exercise. Rewind when not clear Ask Questions by call or SMS or by mail Keep Watching Keep Learning THIS IS PREPROCESSOR
  • 3. Preprocessor • Preprocessor processes source program before it is passed to compiler. preprocessor Compiler • Produce a source code file with the preprocessing commands properly sorted out.
  • 4. Preprocessor Directives • Preprocessor commands are known as directives. • Preprocessor provides certain features. • These features are also known as preprocessor directives. • Preprocessor directives start with # sign. #include <stdio.h>
  • 5. Preprocessor Directives... • Preprocessor directives can be placed any where in the source program. • Note: Place it at start of the program. • Each preprocessor directive must be on it’s own line. #include <stdio.h> #include <stdio.h> #include <conio.h> #include <conio.h>
  • 6. Preprocessor Directives • Macro Expansion • File Inclusion • Conditional compilation • Miscellaneous directives
  • 7. Macro Expansion • #define directive is known as macro expansion. • Definition: #define PI 3.1415 • General Form: – #define macro_template macro_expansion – #define macro_name char_sequence
  • 8. Macro Expansion... • Preprocessor search for macro definition. • After finding #define directive it search entire program for macro_template. • Replace each macro_template with macro_expansion. • Best Practice: Use capital letters for macro template. • Do not use semicolon ‘ ; ’
  • 9. Macros, Why? • To write efficient programs. • To increase readiabiality of programs. • Variable vs macro_template – Compiler can generate faster and compact code for constant than it can for variables. – When you are dealing with a constant, why use variable. – A variable may change in the program.
  • 10. Macros, Where? • Replace operator: #define AND && #define OR || • Replace condition: #define EXCELLENT (a>=75) • Replace statement: #define ALERT printf(“Security Alert”);
  • 11. Macros... • Defined macro name can be used as a part of definition of other macro name. #define MIN 1 #define MAX 9 #define MIDDLE (MAX-MIN)/2 • No text substitution occur if the identifier is within a quoted string.
  • 12. Macros with Arguments • Macros can have arguments, same as functions #define ISEXCELLENT(x) (x >= 75) #define ISLOWER(x) (x>=97 && x<=122) • Note: Space between Macro and it’s arguments. ISLOWER(x) ISLOWER (x)
  • 13. Macros with Arguments... • Macros expansions should be enclosed within paranthesis. #define ISLOWER(x) (x>=97 && x<=122) if(!ISLOWER(‘a’)); • Use ‘’ to split macro in multiple line. #define HLINE for(i=0; i < 40; i++) printf(“_”);
  • 14. Macros vs Functions MACROS FUNCTIONS Just the replacement of the Passing arguments, doing code. calculation, returning results. (More serious work). Macros make the program run Function calls and return make faster. the program slow. Increase the program size Make program smaller and compact.
  • 15. File Inclusion • causes one file to be included in another. #include <filename> //OR #include “filename” • <filename> : search the directory on current directory only. • “filename” : search the directory on current directory and specified directories as specified in the include search path.
  • 16. Why File Inclusion? • Divide a program in multiple files. – Each file contains related functions. • Some functions or macros are required in each program – Put them in a file (Library). – Include them in program that need them. • Nested includes: Included file may have more included files in it.
  • 17. Conditional Compilation • Write single program to run on different environments. – #ifdef – if defined – #endif – end if – #else – else – #ifndef – in not defined – #if – if – #elif – else if
  • 18. #ifdef & #endif • General form: #ifdef macroname statement sequence #endif • if macroname has been defined using #define the code between #ifdef & #endif will execute.
  • 19. #else • Use #else with #ifdef same as else with if. • General-form: #ifdef macroname statement sequence #else statement sequence #endif
  • 20. #ifndef • #ifndef is just opposite to #ifdef. #ifndef __file_h #define __file_h • #if directive test whether an expression evaluates to nonzero value or not. • #elif used same as else if.
  • 21. Where conditional compilation? • Instead of comments. – Nested comments not allowed in C. /* #ifdef BLOCK for(i =0; i<=students;i++) for(i =0; i<=students;i++) count++; /*total students*/ count++; /*total students*/ printf(“%d”,count); printf(“%d”,count); */ #endif
  • 22. Where conditional compilation? • Run the same code on different environment. #ifdef WINDOWS statement sequence #else statemet sequence #endif
  • 23. Where conditional compilation? • To avoide multiple declaration error. # # < < > > # < >
  • 24. To get complete benefit of this tutorial solve all the quiz on www.learnbywatch.com For any problem in this tutorial mail me at [email protected] with the subject “C” For Other information mail at [email protected]