c++ quiz 5
This operator represents the logical AND.
&&
What does the following code display? int i=0, j=0, k=0; k = (i && j++); cout << i << ", "<< j << ", "<< k;
0 0 0
What will the following program display? #include <iostream> using namespace std; int main() { int a = 0, b = 2, x = 4, y = 0; cout << (a == b) << " "; cout << (a != b) << " "; cout << (b <= x) << " "; cout << (y > a) << endl; return 0; }
0 1 1 0
What will the following program segment display? int funny = 7, serious = 15; funny = serious % 2; if (funny != 1) { funny = serious = 0; } else if (funny == 2) { funny = serious = 10; } else { funny = serious = 1; } cout << funny << " " << serious << endl;
1 1
After execution of the following code, what will be the value of input_value if the value 0 is entered at the keyboard at run time? cin >> input_value; if (input_value > 5) input_value = input_value + 5; else if (input_value > 2) input_value = input_value + 10; else input_value = input_value + 15;
15
If you place a semicolon after the following statement: if (x < y)
The compiler will interpret the semicolon as a null statement.
Relational operators allow you to ________ numbers.
compare
Using your knowledge of DeMorgan's Rule, will the following statements yield the same result? bool a, b, c; ( a && b || !c && !a); ! (!a || !b && c || a);
true treat it as a factor like in algebra ! factored out of the initial expression !*! cancel the not! !*|| is &&
The following two relational statements will evaluate the same result ? bool a, b, c, d; d = a || b && c; d = a || ( b && c );
true, parentheses are used to group
What will the following segment of code display assuming the user enters a grade of 90 from the keyboard? cout << "Enter a test score: "; cin >> test_score; if (test_score < 60); cout << "You failed the test! "; if (test_score > 60) cout << "You passed the test! "; else cout << "You need to study for the next test! ";
you failed the test! You passed the test!