Shared Flashcard Set

Details

Chapter 3: More Flow of Control
Using boolean expressions, multiway branches, more about c++ loop statements, designing loops
12
Computer Science
Undergraduate 1
04/13/2012

Additional Computer Science Flashcards

 


 

Cards

Term
What is an enumeration type?
Definition
An enumeration type is a type whose values are defined by a list of constants of type int. If no values are declared, the identifiers are assigned consecutive values beginning with 0.
Term
What is a dangling else problem?
Definition

It is when the compiler uses the second interpretation and will pair the one else with the second if rather than the first if. The compiler will always pair an else statement with the nearest if statement. Solution is to use braces.

Ex. Code: if ( ) { if ( ) } else { ...}

This allows the first if to be paired with the else.

Term
What is the compiler's flow of thought on an if-else-if-else statement?
Definition
The compiler will read each statement in order and evaluate its truth. The compiler will continue to read until it finds a true condition. If it doesn't find a true statement, no action is taken. If the statement ends only with an else statement without a preceding if then all the conditions are false.
Term
What is the structure of a switch statement?
Definition

switch (variable being evaluated)

{

     case 'input 1':

          blah blah;

          break;

     case 'imput 2':

          break;

     default:

          blah;

}

 

Term
What is a controlling expression?
Definition
The controlling expression determines what choice of which branch is executed. It is the variable in ( ) after the reserved word 'switch'.
Term
How would you implement two case labels for a switch?
Definition

case 'A':

case 'a':

Term
What is the rule for an identifier declared in each of 2 blocks?
Definition
This variable is treated as 2 different variables and any changes will only be implemented to one.
Term
What is the major difference between a while loop and a do-while loop?
Definition
A while loop is evaluated first and if proved to be true, executed. A do-while loop is executed one time then repeated if the while statement is true.
Term

What is the difference between

number = 2

 

a) 2 * (number++)

and

b) 2 * (++number)

Definition

a) This equation will output 4. The value will increment after the equation is evaluated.

b) This equation will output 6. The value will increment before the operation is implemented.

Term
What is a for loop?
Definition

A for loop is a special while-like loop that is more compact. Only use for loops when the loop is controlled by one variable.

 

Term
What is the structure of a for loop?
Definition

The structure of a for loop is

for (initialization of variable; bool. expression;

update action).

Bool. expression is the condition to determine whether the loop should be continued. The update action, such as x++, determines how the variable is updated after every iteration. There is no semi-colon at the end.

Term
What are the four ways to end a loop?
Definition

1. List headed by size

2. Ask before iterating

3. List ended with a sentinel value

4. Running out of input

Supporting users have an ad free experience!