Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Programming

Similar presentations


Presentation on theme: "Introduction to Programming"— Presentation transcript:

1 Introduction to Programming
Lecture 23 Preprocessors and Header files

2 Today’s Lecture Preprocessor Directives Header Files Macros

3 Preprocessor

4 #include <iostream.h>

5 #

6 #include #include <iostream.h> #include <stdlib.h>
#include <fstream.h> #include <stream.h>

7 5:10 to 5:23

8 5:24 to 5:41

9 Re-locatable Executable

10 MyHeader.h

11 #include “MyHeader.h”

12 #include <iostream.h>

13

14 #define

15 #define PI

16 Preprocessor Directives
#if #else #endif #elif #ifdef #ifndef #error

17 Preprocessor Directives
#ident #import #line #machine #system #warning

18 Example #ifdef PI

19 # define PI # ifdef PI

20 # define DEBUG # ifdef DEBUG

21 Conditional Compilation Macro Translation

22 #undef DEBUG

23 #include <conio.h>
#include <conio.h> Consol Input Output

24 #include <conio.h> #include <conio.c>

25 int getche ( ) ;

26 Get Character With Echo

27 #ifdef __cplusplus extern "C" { #endif - - }

28 Macro

29 Example 1 #define SQUARE ( X ) X * X main ( ) { int i = 5 , j ; : }
i * i ; SQUARE ( i ) ;

30 Example 2 #define SQUARE ( X ) X * X main ( ) {
int i = 5 , j = 10 , k ; : k = } i + j * i + j ; SQUARE ( i + j ) ;

31 Example 3 #define SQUARE(X) (X)*(X) main ( ) {
int i = 5 , j = 10 , k ; k = } SQUARE ( i + j ) ; ( i + j ) * ( i + j ) ;

32 Overhead

33 Code Bloat

34 Example 4 #define PI 3.14159 #define CIRCLEAREA ( X ) main ( ) {
float radius ; cout << “ Enter radius of Circle Area : ” ; cin >> radius ; cout << “ Area of Circle Area is ” << } ( ( PI ) * ( X ) * ( X ) ) PI * X * X CIRCLEAREA ( 2 * radius ) ; CIRCLEAREA ( radius ) ; ( ( PI ) * ( radius ) * ( radius ) ) ;

35 Header Files

36 Header File #include <iostream.h> #include <stdlib.h>
#include <stdio.h> #include <string.h>

37 In Next Lecture Memory Allocation


Download ppt "Introduction to Programming"

Similar presentations


Ads by Google