Deck 4: Control Statements, Assignment, and Operators
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/29
Play
Full screen (f)
Deck 4: Control Statements, Assignment, and Operators
1
How many times will the following loop print hello? i = 1;
While (i <= 10) {
Cout << "hello";
}
A) 0.
B) 9.
C) 10.
D) An infinite number of times.
While (i <= 10) {
Cout << "hello";
}
A) 0.
B) 9.
C) 10.
D) An infinite number of times.
D
2
Which of the following is true of pseudocode?
A) It is executed by the computer.
B) It helps the programmer "think out" a program.
C) It includes declarations and all types of statements.
D) All of the above are false.
A) It is executed by the computer.
B) It helps the programmer "think out" a program.
C) It includes declarations and all types of statements.
D) All of the above are false.
B
3
In an activity diagram for an algorithm, what does a solid circle surrounded by a hollow circle represent?
A) Initial state.
B) Final state.
C) Action state.
D) Transition.
A) Initial state.
B) Final state.
C) Action state.
D) Transition.
B
4
Which of the following encompasses the other three?
A) Sequence structure.
B) Repetition structure.
C) Control structure.
D) Selection structure.
A) Sequence structure.
B) Repetition structure.
C) Control structure.
D) Selection structure.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
5
Specifying the order in which statements are to be executed in a computer program is called:
A) An algorithm.
B) Transfer of control.
C) Program control.
D) Pseudocode.
A) An algorithm.
B) Transfer of control.
C) Program control.
D) Pseudocode.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
6
Which operation does not take place in the following example? int x{21};
Double y{6};
Double z{14};
Y = x / z;
X = 5.5 * y;
A) Implicit conversion.
B) Promotion.
C) Explicit conversion.
D) Truncation.
Double y{6};
Double z{14};
Y = x / z;
X = 5.5 * y;
A) Implicit conversion.
B) Promotion.
C) Explicit conversion.
D) Truncation.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
7
Pseudocode normally does not include:
A) Declarations.
B) Input/output.
C) Algorithms.
D) Control structures.
A) Declarations.
B) Input/output.
C) Algorithms.
D) Control structures.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
8
The conditional operator (?:):
A) Is the only ternary operator in C++.
B) Is a unary operator.
C) Associates from left to right.
D) Accepts two operands.
A) Is the only ternary operator in C++.
B) Is a unary operator.
C) Associates from left to right.
D) Accepts two operands.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
9
What is wrong with the following while loop? while (sum <= 1000) {
Sum = sum - 30;
}
A) The parentheses should be braces.
B) There should be a semicolon after while (sum <= 1000).
C) sum = sum - 30 should be sum = sum + 30 or else the loop may never end.
D) None of the above.
Sum = sum - 30;
}
A) The parentheses should be braces.
B) There should be a semicolon after while (sum <= 1000).
C) sum = sum - 30 should be sum = sum + 30 or else the loop may never end.
D) None of the above.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
10
A block:
A) Must contain exactly three statements.
B) Cannot contain declarations.
C) Is a compound statement.
D) Is represented by placing a semicolon (;) where a statement would normally be.
A) Must contain exactly three statements.
B) Cannot contain declarations.
C) Is a compound statement.
D) Is represented by placing a semicolon (;) where a statement would normally be.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
11
Using a while loop's counter-control variable in a calculation after the loop ends often causes a common logic error called:
A) A fatal logic error.
B) A counter exception.
C) A syntax error.
D) An off-by-one error.
A) A fatal logic error.
B) A counter exception.
C) A syntax error.
D) An off-by-one error.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
12
An uninitialized local variable contains:
A) The value last stored in the memory location reserved for that variable.
B) No value.
C) A value of zero.
D) A randomly assigned value.
A) The value last stored in the memory location reserved for that variable.
B) No value.
C) A value of zero.
D) A randomly assigned value.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
13
If grade has the value of 60, what will the following code display? if (grade >= 60) {
Cout << "Passed";
}
A) nothing.
B) 60
C) Passed
D) cout << "Passed";
Cout << "Passed";
}
A) nothing.
B) 60
C) Passed
D) cout << "Passed";
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
14
The data type bool:
A) Can take on values true and false.
B) Can take on any expression as a value.
C) Can take on values -1, 0 or 1.
D) Can only be used in a selection statement.
A) Can take on values true and false.
B) Can take on any expression as a value.
C) Can take on values -1, 0 or 1.
D) Can only be used in a selection statement.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following is a double-selection statement?
A) if.
B) if…else.
C) do…while.
D) switch.
A) if.
B) if…else.
C) do…while.
D) switch.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
16
What is the final value of x after performing the following operations? int x{21};
Double y{6};
Double z{14};
Y = x / z;
X = 5.5 * y;
A) 8.25.
B) 5.5.
C) 5.
D) 8.
Double y{6};
Double z{14};
Y = x / z;
X = 5.5 * y;
A) 8.25.
B) 5.5.
C) 5.
D) 8.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following statements about nested if…else statements is true?
A) An if…else statement may not be nested in another nested if…else.
B) Each if…else statement must contain only a simple condition.
C) In an if body, an inner if…else executes only if the outer if statement's condition is true.
D) The statement(s) in an inner if always execute(s) if its condition is true.
A) An if…else statement may not be nested in another nested if…else.
B) Each if…else statement must contain only a simple condition.
C) In an if body, an inner if…else executes only if the outer if statement's condition is true.
D) The statement(s) in an inner if always execute(s) if its condition is true.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following is a repetition structure?
A) if.
B) if…else.
C) do…while.
D) switch.
A) if.
B) if…else.
C) do…while.
D) switch.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following is not a keyword that was added to C++ in the new C++11 standard?
A) nullptr.
B) operator.
C) constexpr.
D) noexcept.
A) nullptr.
B) operator.
C) constexpr.
D) noexcept.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following does not display correct if answer is equal to 7 and incorrect if answer is not equal to 7?
A) if (answer == 7) { cout << "correct";
}
Else {
Cout << "incorrect";
}
B) cout << answer == 7 ? "correct" : "incorrect";
C) cout << (answer == 7 ? "correct" : "incorrect");
D) answer == 7 ? cout << "correct" : cout << "incorrect";
A) if (answer == 7) { cout << "correct";
}
Else {
Cout << "incorrect";
}
B) cout << answer == 7 ? "correct" : "incorrect";
C) cout << (answer == 7 ? "correct" : "incorrect");
D) answer == 7 ? cout << "correct" : cout << "incorrect";
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following statements initializes the unsigned int variable counter to 10?
A) unsigned int counter = 10;
B) unsigned int counter = {10};
C) unsigned int counter{10};
D) All of the above.
A) unsigned int counter = 10;
B) unsigned int counter = {10};
C) unsigned int counter{10};
D) All of the above.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
22
Assuming that x is equal to 4, which of the following statements will not result in y containing the value 5 after execution?
A) y = 5;
B) y = x++;
C) y = ++x;
D) y = x + 1
A) y = 5;
B) y = x++;
C) y = ++x;
D) y = x + 1
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following is true?
A) Assigning a double value to an int does not lose any data.
B) For fundamental-type variables, list-initialization syntax prevents narrowing conversions that could result in data loss.
C) For fundamental-type variables, list-initialization syntax allows narrowing conversions that could result in data loss.
D) None of the above.
A) Assigning a double value to an int does not lose any data.
B) For fundamental-type variables, list-initialization syntax prevents narrowing conversions that could result in data loss.
C) For fundamental-type variables, list-initialization syntax allows narrowing conversions that could result in data loss.
D) None of the above.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
24
Assuming that x and y are equal to 3 and 2, respectively, after the statement x -= y executes, the values of x and y will be:
A) x: 5; y: 3
B) x: 3; y: -1
C) x: 3; y: 5
D) x: 1; y: 2
A) x: 5; y: 3
B) x: 3; y: -1
C) x: 3; y: 5
D) x: 1; y: 2
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following will not increment c by 1?
A) c + 1;
B) c++;
C) ++c;
D) c += 1;
A) c + 1;
B) c++;
C) ++c;
D) c += 1;
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
26
Having a loop within a loop is known as:
A) Recursion.
B) Doubling up.
C) Nesting.
D) Stacking.
A) Recursion.
B) Doubling up.
C) Nesting.
D) Stacking.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
27
If x initially contains the value 3, which of the following sets x to 7?
A) x ++ 4;
B) x += 4;
C) x =+ 4;
D) x + 4 = x;
A) x ++ 4;
B) x += 4;
C) x =+ 4;
D) x + 4 = x;
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
28
Which of the following statements is false?
A) C++ requires all variables to have a type.
B) C++ fundamental types are portable.
C) ints may be 64 bits on some machines.
D) C++ programmers frequently have to write different versions of programs for different platforms.
A) C++ requires all variables to have a type.
B) C++ fundamental types are portable.
C) ints may be 64 bits on some machines.
D) C++ programmers frequently have to write different versions of programs for different platforms.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following operations has the highest precedence?
A) Postincrement.
B) Multiplication.
C) Addition.
D) Assignment.
A) Postincrement.
B) Multiplication.
C) Addition.
D) Assignment.
Unlock Deck
Unlock for access to all 29 flashcards in this deck.
Unlock Deck
k this deck