Sams Teach Yourself C++ in 21 Days

(singke) #1
Exercises ........................................................................................................


  1. This program initializes two integer variables (numbers) and then prints out their
    sum, 12, and their product, 35.

  2. See your compiler manual.

  3. You must put a #symbol before the word includeon the first line.

  4. This program prints the words Hello Worldto the console, followed by a new line
    (carriage return).


Day 2....................................................................................................................


Quiz ................................................................................................................


  1. Each time you run your compiler, the preprocessor runs first. It reads through your
    source code and includes the files you’ve asked for, and performs other housekeep-
    ing chores. The compiler is then run to convert your preprocessed source code to
    object code.
    2.main()is special because it is called automatically each time your program is
    executed. It might not be called by any other function and it must exist in every
    program.

  2. C++-style, single-line comments are started with two slashes (//) and they com-
    ment out any text until the end of the line. Multiline, or C-style, comments are
    identified with marker pairs (/ /), and everything between the matching pairs is
    commented out. You must be careful to ensure you have matched pairs.

  3. C++-style, single-line comments can be nested within multiline, C-style comments:
    / This marker starts a comment. Everything including
    // this single line comment,
    is ignored as a comment until the end marker
    /
    You can, in fact, nest slash-star style comments within double-slash, C++-style
    comments as long as you remember that the C++-style comments end at the end of
    the line.

  4. Multiline, C-style comments can be longer than one line. If you want to extend
    C++-style, single-line comments to a second line, you must put another set of dou-
    ble slashes (//).


822 Appendix D

32 0672327112_app_d.qxd 11/19/04 12:30 PM Page 822

Free download pdf