Questions
Answers to these questions can be found in Appendix G.
A relational operator
-
assigns one operand to another.
-
yields a Boolean result.
-
compares two operands.
-
logically combines two operands.
Write an expression that uses a relational operator to return true if the variable george is not equal to sally.
Is 1 true or false?
Name and describe the usual purpose of three expressions in a for statement.
In a for loop with a multistatement loop body, semicolons should appear following
-
the for statement itself.
-
the closing brace in a multistatement loop body.
-
each statement within the loop body.
-
the test expression.
True or false: The increment expression in a for loop can decrement the loop variable.
Write a for loop that displays the numbers from 100 to 110.
A block of code is delimited by ________________.
A variable defined within a block is visible
-
from the point of definition onward in the program.
-
from the point of definition onward in the function.
-
from the point of definition onward in the block.
-
throughout the function.
Write a while loop that displays the numbers from 100 to 110.
True or false: Relational operators have a higher precedence than arithmetic operators.
How many times is the loop body executed in a do loop?
Write a do loop that displays the numbers from 100 to 110.
Write an if statement that prints Yes if a variable age is greater than 21.
The library function exit() causes an exit from
-
the loop in which it occurs.
-
the block in which it occurs.
-
the function in which it occurs.
-
the program in which it occurs.
Write an if...else statement that displays Yes if a variable age is greater than 21, and displays No otherwise.
The getche() library function
-
returns a character when any key is pressed.
-
returns a character when Enter is pressed.
-
displays a character on the screen when any key is pressed.
-
does not display a character on the screen.
What is the character obtained from cin when the user presses the Enter key?
An else always matches the _________ if, unless the if is _________.
The else...if construction is obtained from a nested if...else by ________________.
Write a switch statement that prints Yes if a variable ch is 'y', prints No if ch is 'n', and prints Unknown response otherwise.
Write a statement that uses a conditional operator to set ticket to 1 if speed is greater than 55, and to 0 otherwise.
The && and || operators
-
compare two numeric values.
-
combine two numeric values.
-
compare two Boolean values.
-
combine two Boolean values.
Write an expression involving a logical operator that is true if limit is 55 and speed is greater than 55.
Arrange in order of precedence (highest first) the following kinds of operators: logical, unary, arithmetic, assignment, relational, conditional.
The break statement causes an exit
-
only from the innermost loop.
-
only from the innermost switch.
-
from all loops and switches.
-
from the innermost loop or switch.
Executing the continue operator from within a loop causes control to go to ________.
The goto statement causes control to go to
-
an operator.
-
a label.
-
a variable.
-
a function.