SlideShare a Scribd company logo
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
Ad

More Related Content

What's hot (20)

Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
sangrampatil81
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 
Call by value
Call by valueCall by value
Call by value
Dharani G
 
Pre processor directives in c
Pre processor directives in cPre processor directives in c
Pre processor directives in c
baabtra.com - No. 1 supplier of quality freshers
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
Ashim Lamichhane
 
Functions in python
Functions in pythonFunctions in python
Functions in python
colorsof
 
Introduction of c programming
Introduction of c programmingIntroduction of c programming
Introduction of c programming
Tarun Sharma
 
Syntax analysis
Syntax analysisSyntax analysis
Syntax analysis
Akshaya Arunan
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
Then Murugeshwari
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Type conversion
Type  conversionType  conversion
Type conversion
PreethaPreetha5
 
structure and union
structure and unionstructure and union
structure and union
student
 
Function in C program
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan
 
Data types in python
Data types in pythonData types in python
Data types in python
RaginiJain21
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programming
Rumman Ansari
 
Pointer in c
Pointer in cPointer in c
Pointer in c
lavanya marichamy
 
Python Exception Handling
Python Exception HandlingPython Exception Handling
Python Exception Handling
Megha V
 

Viewers also liked (20)

pre processor directives in C
pre processor directives in Cpre processor directives in C
pre processor directives in C
Sahithi Naraparaju
 
Preprocessor in C
Preprocessor in CPreprocessor in C
Preprocessor in C
Prabhu Govind
 
Preprocessors
Preprocessors Preprocessors
Preprocessors
Gourav Arora
 
Module 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in CModule 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in C
Tushar B Kute
 
The C Preprocessor
The C PreprocessorThe C Preprocessor
The C Preprocessor
iuui
 
Macro
MacroMacro
Macro
Google
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
Manoj Patil
 
C++ Preprocessor Directives
C++ Preprocessor DirectivesC++ Preprocessor Directives
C++ Preprocessor Directives
Wasif Altaf
 
Web Project Presentation - JoinPakForces
Web Project Presentation - JoinPakForcesWeb Project Presentation - JoinPakForces
Web Project Presentation - JoinPakForces
Wasif Altaf
 
Compiler
Compiler Compiler
Compiler
IGZ Software house
 
Implementation of c string functions
Implementation of c string functionsImplementation of c string functions
Implementation of c string functions
mohamed sikander
 
What is c
What is cWhat is c
What is c
Nitesh Saitwal
 
Embedded C workshop
Embedded C workshopEmbedded C workshop
Embedded C workshop
Mostafa El-koumy
 
C string
C stringC string
C string
University of Potsdam
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
String in c
String in cString in c
String in c
Suneel Dogra
 
Assembler
AssemblerAssembler
Assembler
Mohd Arif
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
Embedded C - Lecture 2
Embedded C - Lecture 2Embedded C - Lecture 2
Embedded C - Lecture 2
Mohamed Abdallah
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
Aman Sharma
 
Module 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in CModule 05 Preprocessor and Macros in C
Module 05 Preprocessor and Macros in C
Tushar B Kute
 
The C Preprocessor
The C PreprocessorThe C Preprocessor
The C Preprocessor
iuui
 
System Programming Unit II
System Programming Unit IISystem Programming Unit II
System Programming Unit II
Manoj Patil
 
C++ Preprocessor Directives
C++ Preprocessor DirectivesC++ Preprocessor Directives
C++ Preprocessor Directives
Wasif Altaf
 
Web Project Presentation - JoinPakForces
Web Project Presentation - JoinPakForcesWeb Project Presentation - JoinPakForces
Web Project Presentation - JoinPakForces
Wasif Altaf
 
Implementation of c string functions
Implementation of c string functionsImplementation of c string functions
Implementation of c string functions
mohamed sikander
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C8051 programming skills using EMBEDDED C
8051 programming skills using EMBEDDED C
Aman Sharma
 
Ad

Similar to Preprocessor (20)

UNIT 4A-preprocessor.pptx for c language and basic knowledge
UNIT 4A-preprocessor.pptx for c language and basic knowledgeUNIT 4A-preprocessor.pptx for c language and basic knowledge
UNIT 4A-preprocessor.pptx for c language and basic knowledge
2024163103shubham
 
C programming session6
C programming  session6C programming  session6
C programming session6
Keroles karam khalil
 
05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
Hector Garzo
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
lalithambiga kamaraj
 
Preprocessor
PreprocessorPreprocessor
Preprocessor
abhay singh
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
Tanmay Modi
 
PreProcessorDirective.ppt
PreProcessorDirective.pptPreProcessorDirective.ppt
PreProcessorDirective.ppt
Osmania University
 
Presentation1.pdf programing fundamental
Presentation1.pdf programing fundamentalPresentation1.pdf programing fundamental
Presentation1.pdf programing fundamental
k8237344
 
Chtp413
Chtp413Chtp413
Chtp413
giovanniveitch
 
1 - Preprocessor.pptx
1 - Preprocessor.pptx1 - Preprocessor.pptx
1 - Preprocessor.pptx
AlAmos4
 
Preprocesser in c
Preprocesser in cPreprocesser in c
Preprocesser in c
Muhammed Thanveer M
 
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdf
KalighatOkira
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
Mark Niebergall
 
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
 
Modular programming
Modular programmingModular programming
Modular programming
Mohanlal Sukhadia University (MLSU)
 
Unit 4-6 sem 7 Web Technologies.pptx
Unit 4-6 sem 7    Web  Technologies.pptxUnit 4-6 sem 7    Web  Technologies.pptx
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Yasuko Ohba
 
UNIT 4A-preprocessor.pptx for c language and basic knowledge
UNIT 4A-preprocessor.pptx for c language and basic knowledgeUNIT 4A-preprocessor.pptx for c language and basic knowledge
UNIT 4A-preprocessor.pptx for c language and basic knowledge
2024163103shubham
 
05 -working_with_the_preproce
05  -working_with_the_preproce05  -working_with_the_preproce
05 -working_with_the_preproce
Hector Garzo
 
Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
Tanmay Modi
 
Presentation1.pdf programing fundamental
Presentation1.pdf programing fundamentalPresentation1.pdf programing fundamental
Presentation1.pdf programing fundamental
k8237344
 
1 - Preprocessor.pptx
1 - Preprocessor.pptx1 - Preprocessor.pptx
1 - Preprocessor.pptx
AlAmos4
 
Basics of C Prog Lang.pdf
Basics of C Prog Lang.pdfBasics of C Prog Lang.pdf
Basics of C Prog Lang.pdf
KalighatOkira
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
Mark Niebergall
 
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
 
Unit 4-6 sem 7 Web Technologies.pptx
Unit 4-6 sem 7    Web  Technologies.pptxUnit 4-6 sem 7    Web  Technologies.pptx
Unit 4-6 sem 7 Web Technologies.pptx
prathameshp9922
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Yasuko Ohba
 
Ad

More from Learn By Watch (20)

Tutorial 9 fm
Tutorial 9 fmTutorial 9 fm
Tutorial 9 fm
Learn By Watch
 
Phase modulation
Phase modulationPhase modulation
Phase modulation
Learn By Watch
 
Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detector
Learn By Watch
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detector
Learn By Watch
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong method
Learn By Watch
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator method
Learn By Watch
 
Carson's rule
Carson's ruleCarson's rule
Carson's rule
Learn By Watch
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfm
Learn By Watch
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfm
Learn By Watch
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signal
Learn By Watch
 
Angle modulation
Angle modulationAngle modulation
Angle modulation
Learn By Watch
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexing
Learn By Watch
 
Vsb modulation
Vsb modulationVsb modulation
Vsb modulation
Learn By Watch
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detector
Learn By Watch
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination method
Learn By Watch
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination method
Learn By Watch
 
Ssb modulation
Ssb modulationSsb modulation
Ssb modulation
Learn By Watch
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiver
Learn By Watch
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qam
Learn By Watch
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detector
Learn By Watch
 
Demodulation of fm pll detector
Demodulation of fm pll detectorDemodulation of fm pll detector
Demodulation of fm pll detector
Learn By Watch
 
Demodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detectorDemodulation of fm slope and balanced slope detector
Demodulation of fm slope and balanced slope detector
Learn By Watch
 
In direct method of fm generation armstrong method
In direct method of fm generation armstrong methodIn direct method of fm generation armstrong method
In direct method of fm generation armstrong method
Learn By Watch
 
Direct method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator methodDirect method of fm generation hartley oscillator method
Direct method of fm generation hartley oscillator method
Learn By Watch
 
Spectrum and power of wbfm
Spectrum and power of wbfmSpectrum and power of wbfm
Spectrum and power of wbfm
Learn By Watch
 
Narrow band frequency modulation nbfm
Narrow band frequency modulation nbfmNarrow band frequency modulation nbfm
Narrow band frequency modulation nbfm
Learn By Watch
 
General expression of fm signal
General expression of fm signalGeneral expression of fm signal
General expression of fm signal
Learn By Watch
 
Frequency division multiplexing
Frequency division multiplexingFrequency division multiplexing
Frequency division multiplexing
Learn By Watch
 
Demodulation of ssb synchronous detector
Demodulation of ssb synchronous detectorDemodulation of ssb synchronous detector
Demodulation of ssb synchronous detector
Learn By Watch
 
Generarion of ssb phase discrimination method
Generarion of ssb phase discrimination methodGenerarion of ssb phase discrimination method
Generarion of ssb phase discrimination method
Learn By Watch
 
Generarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination methodGenerarion of ssb frequency discrimination method
Generarion of ssb frequency discrimination method
Learn By Watch
 
Demodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiverDemodulation of dsb sc costas receiver
Demodulation of dsb sc costas receiver
Learn By Watch
 
Quadrature carrier multiplexing qam
Quadrature carrier multiplexing qamQuadrature carrier multiplexing qam
Quadrature carrier multiplexing qam
Learn By Watch
 
Demodulation of am synchronous detector
Demodulation of am synchronous detectorDemodulation of am synchronous detector
Demodulation of am synchronous detector
Learn By Watch
 

Preprocessor

  • 1. C Programming Language By: Yogendra Pal yogendra@learnbywatch.com 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 yogendra@learnbywatch.com with the subject “C” For Other information mail at info@learnbywatch.com
  翻译: