Chapter 5 Flashcards
Looping
[Blank] are C++ operators the change their operands by one.
++ and –
True/False: To decrement a number means to increase its value.
False
The ++ operator
Is a unary operator, adds one the the value of its operand, and can operate in prefix or postfix mode.
What will the following code print?
num = 8;
cout «_space;–num «_space;” “;
cout «_space;num++ «_space;” “;
cout «_space;num;
7 7 8
The while loop has two important parts: a condition that is tested and a statement or block of statements that is …
repeated as long as the condition is true.
True/False: The block of code in the body of a while statement can contain an unlimited number of statements, provided they are enclosed in a set of braces.
True
True/False: A while loop may have a semicolon after the test expression and before the body of the loop, but it is not required.
False
True/False: A while loop is somewhat limited, because the counter can only count up, not down.
False
The while loop is a(n) [Blank] loop, where as the do-while loop is a(n) [Blank] loop.
pretest, post test
The statements in the body of a do-while loop are executed …
at least once
A sentinel is a special value that …
marks the end of a list of values
A for statement contains three expressions: initialization, test, and …
update
In a for statement, the [Blank] expression is executed only once.
initialization
True/False: An initialization expression may be omitted from the for loop if no initialization is required.
True
You may define a(n) [Blank] in the initialization expression of a for loop.
variable