Skip to main content
Contents
Dark Mode Prev Up Next Scratch ActiveCode Profile
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
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:
Everything in C++ must be declared as a specific type of object or variable, including declaring the return type for each function.
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.
C++ statements are ended by a semi-colon.
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++.
One of the above is correct.
2.
True or False: In both Python and C++, multi-line comments begin with ``/*`` and end with ``*/``.
Sorry, multi-line comments are possible in both languages, but they look different.
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?
Partially right. The object `cout` stands for character output and you need it, but you will also need to use the insertion operator <<.
No, output is not a C++ command or object.
No, print is a Python command, but is not used in C++.
The correct statement would be "cout << x;" or "std:cout << x;" but the insertion operator is certainly needed.
4.
5.
6.
7.
You have attempted
of
activities on this page.