Answers to Self-Review Exercises

  1. 2.1

    1. main.

    2. left brace ({), right brace (}).

    3. semicolon.

    4. newline.

    5. if.

  2. 2.2

    1. False. Comments do not cause any action to be performed when the program is executed. They’re used to document programs and improve their readability.

    2. True.

    3. True.

    4. True.

    5. False. C++ is case sensitive, so these variables are different.

    6. True.

    7. True.

    8. False. The operators *, / and % have the same precedence, and the operators + and - have a lower precedence.

    9. False. One statement with cout and multiple \n escape sequences can print several lines.

  3. 2.3

    1. int c{0}, thisIsAVariable{0}, q76354{0}, number{0};

    2. std::cout << "Enter an integer: ";

    3. std::cin >> age;

    4.  

      
      if (number != 7) {
         std::cout << "The variable number is not equal to 7\n";
      }
      
    5. std::cout ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.