C++ - Chapter 4 Review

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

The __________ logical operator has higher precedence than the other logical operators.

!

If the sub-expression on the left of the __________ logical operator is false, the right sub-expression is not checked.

& &

The __________ logical operator works best when testing a number to determine if it is within a range.

& &

If the sub-expression on the left of the __________ logical operator is true, the right sub-expression is not checked.

| |

The __________ logical operator works best when testing a number to determine if it is outside a range.

| |

An expression using the greater-than, less-than, greater-than-or-equal to, less-than or equal-to, equal, or not-equal to operator is called a(n) __________ expression.

relational

T F A conditionally executed statement should be indented one level from the if statement.

true

T F All lines in a block should be indented one level.

true

T F The scope of a variable is limited to the block in which it is defined.

true

T F When an if statement is nested in the if part of another statement, the only time the inner if is executed is when the expression of the outer if is true.

true

T F You can use the relational operators to compare string objects.

true

Describe the difference between the if/else if statement and a series of if statements.

In an if/else if statement, the conditions are tested until one is found to be true. The conditionally executed statement(s) are executed and the program exits the if/else if statement. In a series of if statements, all of the if statements execute and test their conditions because they are not connected.

In an if/else if statement, what is the purpose of a trailing else?

The trailing else provides code that is executed when none of the conditions in the if/else if statement are true.

A variable with __________ scope is only visible when the program is executing in the block containing the variable's definition.

block

For an if statement to conditionally execute a group of statements, the statements must be enclosed in a set of __________.

braces

A program will "fall through" a case section if it is missing the __________ statement.

break

An expression using the conditional operator is called a(n) __________ expression.

conditional

The trailing else in an if/else if statement has a similar purpose as the __________ section of a switch statement.

default

T F A variable defined in an inner block may not have the same name as a variable defined in the outer block.

false

T F It's safe to assume that all uninitialized variables automatically start with 0 as their value.

false

T F The = operator and the = = operator perform the same operation when used in a Boolean expression.

false

T F When an if statement is nested in the else part of another statement, as in an if/else if, the only time the inner if is executed is when the expression of the outer if is true.

false

T F x >= y is the same as (x > y && x = y)

false

T F y < x is the same as x >= y

false

The if statement regards an expression with the value 0 as __________.

false

You use the __________ operator to determine whether one string object is greater then another string object.

>

What is a flag and how does it work?

A flag is a Boolean variable signaling that some condition exists in the program. When the flag is set to false it indicates the condition does not yet exist. When the flag is set to true it indicates that the condition does exist.

What value will be stored in the variable t after each of the following statements executes? A) t = (12 > 1); __________ B) t = (2 < 0); __________ C) t = (5 = = (3 * 2)); __________ D) t = (5 = = 5); __________

A) 1 B) 0 C) 0 D) 1

Briefly describe how the && operator works.

It takes two expressions as operands and creates a single expression that is true only when both sub-expressions are true.

Briefly describe how the || operator works.

It takes two expressions as operands and creates a single expression that is true when either of the sub-expressions are true.

Why do most programmers indent the conditionally executed statements in a decision structure?

It visually sets the conditionally-executed statements apart from the surrounding code. This is so you can easily identify the code that is conditionally-executed.

Why are the relational operators called relational?

They test for specific relationships between items. The relationships are greater-than, less-than, equal-to, greater-than or equal-to, less-than or equal-to, and not equal-to.

Can an if statement test expressions other than relational expressions? Explain.

Yes. The if statement can test any value that yields a Boolean value (true or false) or a numeric value. When testing a numeric expression, a nonzero numeric value is considered true, and the value 0 is considered false.

The value of a relational expression is 0 if the expression is __________ or 1 if the expression is __________.

false; true

The expression that is tested by a switch statement must have a(n) __________ value.

integer

The expression following a case statement must be a(n) __________ __________.

integer constant

The logical operators have __________ associativity.

left-to-right

The if/else if statement is actually a form of the __________ if statement.

nested

T F x != y is the same as (x > y || x < y)

true

The if statement regards an expression with a non-zero value as __________.

true

A relational expression is either __________ or __________.

true; false

In an if/else statement, the if part executes its statement or block if the expression is __________, and the else part executes its statement or block if the expression is__________.

true; false


संबंधित स्टडी सेट्स

SOS Biology unit 4 Practical Applications in plants

View Set

Chapter 4 Accounting Sample Problems

View Set

MIDTERM 1 MIS 140 CH1 delete after

View Set

GOETHE-ZERTIFIKAT A1: Start Deutsch A1, Sprechen Teil 2 (Fragen formulieren).

View Set

Supply and Demand Recitation Quiz - Ritter

View Set