Answers to Self-Review Exercises

  1. E.1

    1. #.

    2. #elif, #else.

    3. #define.

    4. whitespace.

    5. #undef.

    6. #ifdef, #ifndef.

    7. Conditional compilation.

    8. assert.

    9. #include.

    10. ##.

    11. #.

    12. \.

  2. E.2 (See below.)

    
     1  // exE_02.cpp
     2  // Self-Review Exercise E.2 solution.
     3  #include <iostream>
     4  using namespace std;
     5
     6  int main() {
     7     cout << "__LINE__ = " << __LINE__ << endl
     8          << "__FILE__ = " << __FILE__ << endl
     9          << "__DATE__ = " << __DATE__ << endl
    10          << "__TIME__ = " << __TIME__ << endl
    11          << "__cplusplus = " << __cplusplus << endl;
    12  }  // end main
    
    
    __LINE__ = 9
    __FILE__ = c:\cpp4e\ch19\ex19_02.CPP
    __DATE__ = Jul 17 2002
    __TIME__ = 09:55:58
    __cplusplus = 199711L
    
  3. E.3

    1. #define YES 1

    2. #define NO 0

    3. #include "common.h"

    4.  

      
      #if defined(TRUE)
         #undef TRUE
         #define TRUE 1
      #endif
      
    5.  

Get C++ How to Program, 10/e now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.