cs201- introduction to programming- lecture 23
DESCRIPTION
Virtual University Course CS201- Introduction to Programming Lecture No 23 Instructor's Name: Dr. Naveed A. Malik Course Email: [email protected]TRANSCRIPT
![Page 1: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/1.jpg)
Introduction to Introduction to ProgrammingProgramming
Lecture 23Lecture 23
Preprocessors and Preprocessors and Header filesHeader files
![Page 2: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/2.jpg)
Today’s LectureToday’s Lecture
Preprocessor DirectivesPreprocessor Directives Header FilesHeader Files MacrosMacros
![Page 3: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/3.jpg)
PreprocessPreprocessoror
![Page 4: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/4.jpg)
#include <iostream.h>#include <iostream.h>
![Page 5: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/5.jpg)
##
![Page 6: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/6.jpg)
#include#include #include <iostream.h>#include <iostream.h> #include <stdlib.h>#include <stdlib.h> #include <fstream.h>#include <fstream.h> #include <stream.h>#include <stream.h>
![Page 7: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/7.jpg)
5:10 to 5:23
![Page 8: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/8.jpg)
5:24 to 5:41
![Page 9: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/9.jpg)
Re-locatable Re-locatable ExecutableExecutable
![Page 10: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/10.jpg)
MyHeader.MyHeader.hh
![Page 11: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/11.jpg)
#include “MyHeader.h”#include “MyHeader.h”
![Page 12: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/12.jpg)
#include #include <iostream.h><iostream.h>
![Page 13: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/13.jpg)
![Page 14: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/14.jpg)
#define#define
![Page 15: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/15.jpg)
#define PI #define PI 3.1415923.141592
![Page 16: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/16.jpg)
Preprocessor Preprocessor DirectivesDirectives #if#if #else#else #endif#endif #elif#elif #ifdef#ifdef #ifndef#ifndef #error#error
![Page 17: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/17.jpg)
Preprocessor Preprocessor DirectivesDirectives
#ident#ident #import#import #line#line #machine#machine #system#system #warning#warning
![Page 18: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/18.jpg)
Example Example
#ifdef PI#ifdef PI
![Page 19: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/19.jpg)
# define PI# define PI
# ifdef PI# ifdef PI
![Page 20: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/20.jpg)
# define DEBUG# define DEBUG
# ifdef DEBUG# ifdef DEBUG
![Page 21: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/21.jpg)
Conditional Conditional CompilationCompilation
Macro Macro TranslationTranslation
![Page 22: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/22.jpg)
#undef #undef DEBUGDEBUG
![Page 23: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/23.jpg)
#include #include <conio.h><conio.h>
Consol Input Output Consol Input Output
![Page 24: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/24.jpg)
#include #include <conio.h><conio.h>#include #include
<conio.c><conio.c>
![Page 25: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/25.jpg)
int getche int getche ( ) ;( ) ;
![Page 26: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/26.jpg)
Get Character Get Character With EchoWith Echo
![Page 27: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/27.jpg)
#ifdef __cplusplus#ifdef __cplusplusextern "C" {extern "C" {#endif#endif
- -- -- -- -
#ifdef __cplusplus#ifdef __cplusplus}}#endif#endif
![Page 28: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/28.jpg)
MacroMacro
![Page 29: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/29.jpg)
#define SQUARE ( X ) X * X#define SQUARE ( X ) X * Xmain ( )main ( ){{
int i = 5 , j ;int i = 5 , j ; ::
}}
Example 1Example 1
j =j =SQUARE ( i ) ; SQUARE ( i ) ; i * i ;i * i ;
![Page 30: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/30.jpg)
Example 2 Example 2 ##define SQUARE ( X ) X * Xdefine SQUARE ( X ) X * Xmain ( )main ( ){{
int i = 5 , j = 10 , k ;int i = 5 , j = 10 , k ;::
k =k =}}
SQUARE ( i + j ) ; SQUARE ( i + j ) ; i + j * i + j ;i + j * i + j ;
![Page 31: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/31.jpg)
Example 3Example 3#define SQUARE(X) #define SQUARE(X)
(X)*(X)(X)*(X)
main ( )main ( )
{{
int i = 5 , j = 10 , k ;int i = 5 , j = 10 , k ;
k =k =
}}
SQUARE ( i + j ) ;SQUARE ( i + j ) ;( i + j ) * ( i + j ) ;( i + j ) * ( i + j ) ;
![Page 32: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/32.jpg)
OverheadOverhead
![Page 33: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/33.jpg)
Code BloatCode Bloat
![Page 34: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/34.jpg)
Example 4Example 4#define PI 3.14159#define PI 3.14159#define CIRCLEAREA ( X )#define CIRCLEAREA ( X )main ( )main ( ){{
float radius ;float radius ;cout << “ Enter radius of Circle Area : ” ;cout << “ Enter radius of Circle Area : ” ;cin >> radius ;cin >> radius ;cout << “ Area of Circle Area is ” cout << “ Area of Circle Area is ”
<<<<
}}
PI * X * XPI * X * X( ( PI ) * ( X ) * ( X ) )( ( PI ) * ( X ) * ( X ) )
CIRCLEAREA ( radius ) ;CIRCLEAREA ( radius ) ;( ( PI ) * ( radius ) * ( radius ) ) ;( ( PI ) * ( radius ) * ( radius ) ) ;CIRCLEAREA ( 2 * radius ) ;CIRCLEAREA ( 2 * radius ) ;
![Page 35: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/35.jpg)
Header FilesHeader Files
![Page 36: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/36.jpg)
Header FileHeader File #include #include <iostream.h><iostream.h>
#include <stdlib.h>#include <stdlib.h> #include <stdio.h>#include <stdio.h> #include <string.h>#include <string.h>
![Page 37: CS201- Introduction to Programming- Lecture 23](https://reader033.vdocuments.site/reader033/viewer/2022061303/5492e769b4795900548b45f6/html5/thumbnails/37.jpg)
In Next LectureIn Next Lecture
Memory AllocationMemory Allocation