CS201-23 - Introduction to Programming Lecture 23...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Introduction to Programming Lecture 23 Preprocessors and Header files Today’s Lecture Preprocessor Directives Header Files Macros Preprocessor #include <iostream.h> # #include #include <iostream.h> #include <stdlib.h> #include <fstream.h> #include <stream.h> 5:10 to 5:23 5:24 to 5:41 Re­locatable Executable MyHeader.h #include “MyHeader.h” #include <iostream.h> #define #define PI 3.141592 Preprocessor Directives #if #else #endif #elif #ifdef #ifndef #error Preprocessor Directives #ident #import #line #machine #system #warning Example #ifdef PI # define PI # ifdef PI # define DEBUG # ifdef DEBUG Conditional Compilation Macro Translation #undef DEBUG #include <conio.h> Consol Input Output #include <conio.h> #include <conio.c> int getche ( ) ; Get Character With Echo #ifdef __cplusplus extern "C" { #endif ­ ­ ­ ­ #ifdef __cplusplus } #endif Macro #define SQUARE ( X ) X * X main ( ) { int i = 5 , j ; : j = i * i ; SQUARE ( i ) ; } Example 1 #define SQUARE ( X ) X * X main ( ) { int i = 5 , j = 10 , k ; : i + j * i + j ; k = SQUARE ( i + j ) ; } Example 2 #define SQUARE(X) (X)*(X) main ( ) { int i = 5 , j = 10 , k ; ( i + j ) * ( i + j ) ; k = SQUARE ( i + j ) ; } Example 3 Overhead Code Bloat #define PI 3.14159 #define CIRCLEAREA ( X )PI * X * X ( ( PI ) * ( X ) * ( X ) ) main ( ) { float radius ; cout << “ Enter radius of Circle Area : ” ; cin >> radius ; cout << “ Area of Circle Area is ” ( ( PI ) * ( radius ) * ( radius ) ) ; CIRCLEAREA ( 2 * radius ) ; << CIRCLEAREA ( radius ) ; } Example 4 Header Files Header File #include <iostream.h> #include <stdlib.h> #include <stdio.h> #include <string.h> In Next Lecture Memory Allocation ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern