Chapter 2
Which symbol is used to begin a preprocessor directive?
#
What is the first line of a C++ program?
#include <iostream>
Which of the following preprocessor directives is needed for the string class?
#include <string>
Which of the following is a character literal?
'A'
A group of statements, such as the contents of a function, is enclosed in what?
Braces {}
Unsigned data types can store positive or negative values.
False
When one of the division operator's operands is an integer, the result of the division will also be an integer.
False
You cannot initialize a named constant that is declared with the const modifier.
False
You may choose your own variable names in C++, including any of the C++ key words.
False
This is a programmer-defined name that represents some element of a program.
Identifier
What happens when cout encounters an endl stream manipulator?
It advances the output to the beginning of the next line for subsequent printing
This is like a variable, but its content is read-only and cannot be changed while the program is running.
Named constant
This refers to the way a programmer uses identifiers, spaces, tabs, blank lines, and punctuation characters to visually arrange a program's source code.
Programming Style
Which of the following is a common practice of C++ programming style?
Spreading a statement that is too long to fit on one line over several lines. Indenting all the lines inside a set of braces. Adding a blank line to visually separate definitions from executable statements.
A left brace in a C++ program should always be followed by a right brace later in the program.
True
A variable cannot be used in any part of the program before the definition.
True
Although all of C++'s key words must be written in lowercase, you may use uppercase letters in variable names.
True
An advantage of using named constants is that they make programs more self-documenting.
True
Because C++ is a free-flowing language, it is usually possible to spread a statement over several lines.
True
Boolean expressions are named in honor of English mathematician George Boole.
True
Character literals are enclosed in single quotation marks.
True
Comments are part of the program, but the compiler ignores them.
True
Preprocessor directives are not C++ statements
True
String literals are always stored in memory with a null terminator at the end.
True
The compiler doesn't actually see the #include directive. Instead it sees the code that was inserted by the preprocessor, just as if the programmer had typed it there.
True
The compiler doesn't care that each statement is on a separate line, or that spaces separate operators from operands.
True
The equal sign is an operator that copies the value on its right into the variable named on its left.
True
The scope of a variable is the part of the program where the variable may be used.
True
You must have a definition for every variable you intend to use in a program.
True
You should always choose names for your variables that give an indication of what the variables are used for.
True
shortand short intare the same data type.
True
Causes a double quotation mark to be printed
\"
Causes a single quotation mark to be printed
\'
Causes a backslash to be printed
\\
Causes the computer to beep
\a
Which of the following will assign the value 7 to an integer variable named days?
days = 7;
Which of the following data types can represent floating-point numbers?
float long double double
Which of the following must every C++ program have?
function main
Which of the following data types allows you to store the largest value?
int
Which of the following is a valid variable definition?
int number;
When you assign values to variables as part of the definition, it is called this:
intialization
This header file must be included in any program that uses the cout object.
iostream
The data that operators work with are called what?
operands
This special operator will report the number of bytes of memory used by any data type or variable.
sizeof
Which of the following expressions is an example of a unary operator?
-5
Which of the following is an example of a multi-line comment?
/* Knowledge comes, but wisdom lingers.*/
How much memory does a character normally occupy?
1 byte
Look at the following code. What value will be assigned to the result variable after this code executes? double result; int number1 = 5, number2 = 2; result = number1 / number2;
2
Which of the following does every C++ statement end with?
;
The first step in using the string class is to define a string object.
False
This data type allows you to create small integer variables that are suitable for holding true or false values.
bool
The text of a comment
can be anything the programmer wants to write
These make up the "core" of the C++ language and have specific purposes.
Key words
Causes the cursor to skip over to the next tab stop
\t
Which of the following IS a legal identifier?
____________
The word in the brackets of an include directive specifies
a file containing code that is copied into the program at that point
A preprocessor directive starts with #. Preprocessor directives are carried out
just before a program is processed by the compiler
Which of the following would store the integer literal 64 as a long long int?
lightYears = 64LL;
This is a piece of data that is written directly into a program's code.
literal
Every C++ program must contain a
main function
The preprocessor inserts the entire contents of the file into the program at the point it encounters this.
the #include directive
In C++ terminology, an lvalue is something that identifies a place in memory whose contents may be changed, and an rvalue is any expression that has a value.
true
The =symbol is called the assignment operator.
true
How many operands does a binary operator work with?
two
Which of the following is a specific rule that must be followed with all C++ identifiers?
The first character must be one of the letters a through z, A through Z, or an underscore character (_). Uppercase and lowercase characters are distinct. After the first character you may use the letters a through z or A through Z, the digits 0 through 9, or underscores.
Generally, there are three types of operators: unary, binary, and ternary.
True
Integer variables can hold only whole numbers.
True
One of the problems of portability is the lack of common sizes of data types on all machines.
True
The stream insertion operator is always written as two less-than signs with no space between them
True
There are no unsigned floating point data types.
True
Unless you specify otherwise, the information you send to cout is displayed in a continuous stream
True
Unlike a comment started with //, a multi-line comment can span several lines.
True
When a floating-point value is assigned to an integer variable, the fractional part of the value (the part after the decimal point) is discarded.
True
When string literals are sent to cout they are printed exactly as they appear inside the quotation marks.
True
Working with string objects is similar to working with variables of other types.
True
You can use cout to display the value of a string object.
True
Causes the cursor to back up, or move left one position
\b
Causes the cursor to go to the next line for subsequent printing
\n
Causes the cursor to go the beginning of the current line, not the next line
\r