CS Homework 4
What will the following program segment display? int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " " << (a != y) << " " << (b <= x) << " " << (y > a) << endl;
0 0 1 0
The following if statements are equivalent: if (calls == 20) rate *= 0.5; if (calls = 20) rate *= 0.5;
false
The || operator performs ____________________ evaluation. If the sub-expression on the left side of an || operator is true, the sub-expression on the right side will not be checked because it is only necessary for one of the sub-expressions to be true for the whole expression to evaluate to true.
short circuit
The logical operator && means AND, the result of the operator is:
to connect two expressions into one. Both expressions must be true for the overall expression to be true
The logical operator || means OR, the result of the operator is:
to connect two expressions into one. One or both expressions must be true for the overall expression to be true. It is only necessary for one to be true, and it does not matter which
The logical operator ! means NOT, the result of the operator is:
to reverse the "truth" of an expression. It makes a true expression false, and a false expression true
Assuming x is 5, y is 6, and z is 8, indicate whether the following relational expression is true or false: (2 + x) != y
true
Assuming x is 5, y is 6, and z is 8, indicate whether the following relational expression is true or false: 7 <= (x + 2)
true
Assuming x is 5, y is 6, and z is 8, indicate whether the following relational expression is true or false: x <= (y * 2)
true
Assuming x is 5, y is 6, and z is 8, indicate whether the following relational expression is true or false: x == 5
true
Assuming x is 5, y is 6, and z is 8, indicate whether the following relational expression is true or false: x >= 0
true
Assuming x is 5, y is 6, and z is 8, indicate whether the following relational expression is true or false: z != 4
true
Assuming x is 5, y is 6, and z is 8, indicate whether the following relational expression is true or false: z > 4
true
The following if/else statements cause the same output to display. if (x > y) cout << "x is greater than y.\n"; else cout << "x is not greater than y.\n"; if (x <= y) cout << "x is not greater than y.\n"; else cout << "x is greater than y.\n";
true
The scope of a variable is limited to the block in which it is defined.
true