Skip to main content

Section 1.5 Summary & Reading Questions

Now that we have run our “hello world” program, lets go back and look at it carefully to see what we can learn about the C++ language.
This simple example illustrates a few very important rules:
  1. Everything in C++ must be declared as a specific type of object or variable, including declaring the return type for each function.
  2. Every C++ program must have a function which begins as int main(), and ends with the statement return 0; which returns 0 when successfully completed.
  3. C++ statements are ended by a semi-colon.
  4. White space is mostly meaningless in C++, but all C++ code blocks must be surrounded by curly brackets {}, rather than using indentation to delineate blocks as is done in Python.

Reading Questions Reading Questions

1.

What symbol or set of symbols will begin a comment in C++ when the comment extends only to the end of the line?
  • <!-
  • No, <!- is used in html to begin comments, but it is not used in C++.
  • No, ⋕ is used in Python for comments, but in C++ it is used for compiler directives such as loading a code library.
  • //
  • Correct!
  • No, @ is not used in C++.
  • none of the above
  • One of the above is correct.

2.

True or False: In both Python and C++, multi-line comments begin with ``/*`` and end with ``*/``.
  • True
  • Sorry, multi-line comments are possible in both languages, but they look different.
  • False
  • Right! In C++ multiline comments begin with /* and end with */. In Python, one could use a triple quoted string.

3.

Given a variable called x. What statement will print the contents of x?
  • cout x;
  • Partially right. The object `cout` stands for character output and you need it, but you will also need to use the insertion operator <<.
  • output x;
  • No, output is not a C++ command or object.
  • print x;
  • No, print is a Python command, but is not used in C++.
  • none of the above
  • The correct statement would be "cout << x;" or "std:cout << x;" but the insertion operator is certainly needed.

4.

What keyword from the Standard Library (std) is used in conjunction with the extraction operator to accept C++ input from the keyboard as the standard input?

5.

6.

7.

You have attempted 1 of 7 activities on this page.