Reviews Flashcards

(40 cards)

1
Q

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

A

in an if/else if statement, the conditions are tested until one is found to be true. The conditionally executed statements are executed and the program exits if 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

in an if/else if statement what is the purpose of a trailing else

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a flag and how does it work

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

can an if statement test expressions other than relational expressions? explain

A

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 the value 0 is considered false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

briefly describe how the && operator works

A

it takes two expressions as operands and creates a single expression that is true only when both subexpressions are true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

briefly descrive how the || operator works

A

it takes two expressions as operands and creates a single expression that is true when either of the subepressions are true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

why are the relational operaters called relational

A

because they test for specific relationships between items. The relationships are greater than, less than, equal to, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

relational

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

a relational expression is either ___ or ___

A

true, false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

the value of a relational expression is 0 if the expression is ___ or 1 if the expression is _____.

A

false, true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

the if statement regards an expressison with the value 0 as ___.

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

the if statement regards an expression with a nonzero value as ___.

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

for an if statement to conditionally execute a group of statements, the statements must enclosed in a set of ___.

A

braces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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 ___.

A

true, false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A

default

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

the if/else if statement is actually a form of the ___ if statement

18
Q

If the sub-expression on the left of the __logical operator is false the right sub-expression is not checked

19
Q

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

20
Q

The ___ logical operator has higher precedence than the other logical operators

21
Q

the logical operators have ___ associativity

A

left-to-right

22
Q

the __ logical operators works best when testing a number to determine if it is within range

23
Q

the ___ logical operator works best when testing a number to determine if it is out of range

24
Q

A variable with ___ scope is only visible when the program is executing in the block containing the variable’s definition

25
You use the ___ operator to determine whether one string object is greater than another string object
strings
26
an expression using the conditional operator is a(n) ___ expression.
conditional
27
the expression that is tested by a switch statement must have an __ value
integer
28
the expression following a case statement must be a(n) ____ ___.
integer constant
29
A program will "fall through" a case section if it is missing the ___ statement.
break
30
why should you indent the statements in the body of a loop
by indenting the statements, you make them stand out from the surrounding code. this helps you to identify at a glance the statements that are conditionally executed by a loop
31
describe the difference between pretest loops and posttest loops
a pretest loop tests its condition before each iteration. a posttest loop tests its loop after each iteration. a posttest loop will always execute at least once
32
why are the statements in the body of a loop called conditionally executed statements
because they are only executed when a condition is true
33
what is the difference between the while loop and the do-while loop
the while loop is a prettest loop, the do-qhile loop is a posttest loop.
34
which loop should you use in situations where you wish the loop to repeat until the test expression is false, and the loop should not execute if the test expression is false to begin with?
the while loop
35
which loop should you use in situations where you wish the loop to repeat until the test expression is false, but the loop should execute at least once?
the do-while loop
36
which loop should you use in situations when you know the number of required iterations?
the for loop
37
why is it critical that counter variable be properly initialized?
a counter variable is used to control or keep track of the number of times a loop iterates. In a loop, the counter is usually incremented or decremented. If the counter variable is not properly initialized, it will not hold the correct number.
38
why is it critical the accumulator variables be properly initialized?
an accumulator is used to keep a running total of numbers. In a loop, a value is usually added to the current value of the accumulator. If it is not properly initialized, it will not contain the correct total.
39
why should you be careful not to place a statement in the body of a for loop that changes the value of the loop's counter variable?
because the for lop has an update expression that normally changes the contents of a counter. If you have code inside that loop, that also changes the counter, the loop will not be able to properly control the value of the counter
40
what header file do you need to include in a program that performs file operations?
fstream