Section 3 Review Mr Crone True or false


































- Slides: 34
Section 3 Review Mr. Crone
True or false? bool x = true; int y = 5, z = 6; (y > z && x )
True or false? bool x = true; int y = 5, z = 6; (y > z && x ) // F
True or false? bool x = true; int y = 5, z = 6; (y > z || !x )
True or false? bool x = true; int y = 5, z = 6; (y > z || !x ) // False!
True or false? bool x = true, y = false, z = false (x && !y && !z)
True or false? bool x = true, y = false, z = false (x && !y && !z) True!
What does the code print? int x = 4, y = 2, z = 1; if(y ==2) if( z ==1) x += 6; else x =4; else x += 8; cout << x << endl;
What does the code print? int x = 4, y = 2, z = 1; if(y ==2) // True if( z ==1) // True x += 6; // x = 10 else x =4; else x += 8; cout << x << endl;
What does the code print? int x = 54; if(x>= 5 && x <= 100) x = 4; else x = 5; cout << x << endl;
What does the code print? int x = 54; if(x>= 5 && x <= 100) // True x = 4; // x = 4 else x = 5; cout << x << endl; // 4
What does the code print? bool var = true; bool var 2 = false; if( !(!var && var 2)) cout << “ 1”; else cout << “ 2”;
What does the code print? bool var = true; bool var 2 = false; if( !(!var && var 2)) // True cout << “ 1”; // Prints 1 else cout << “ 2”;
What does the code print? int x = 14; if(x < 10) cout << “ 1”; if (x > 10) cout << “ 2”; if ( x >10 && x < 20) cout << “ 3”; if(x ==10 || x ==14) cout << “ 4”;
What does the code print? int x = 14; if(x < 10) // false cout << “ 1”; if (x > 10) // true cout << “ 2”; if ( x >10 && x < 20) // true cout << “ 3”; if(x ==10 || x ==14) // true cout << “ 4”; Prints: 234
int x = 4; bool var = true; if( var) cout << “ 1” ; else if(x==4) cout << “ 2” ; else if (x ==4 && var) cout << “ 3”; else cout << “ 4”;
What does the code print? int x = 4; bool var = true; if( var)// true cout << “ 1” ; // Prints 1 else if(x==4) cout << “ 2” ; else if (x ==4 && var) cout << “ 3”; else cout << “ 4”;
True or False? bool var = false; bool var 2 = true; cout << (24/4%4>1 || !var && var 2) << endl;
True or False? bool var = false; bool var 2 = true; 24/4%4>1 || !var && var 2 6 % 4 > 1 || T 2 > 1 || T True Prints: 1
const int RADIUS = 3. 14; double num = 5. 5; bool x = false; if(!x) RADIUS += 4; else num= 17; cout << num << endl;
const int RADIUS = 3. 14; // ERROR! double num = 5. 5; bool x = false; if(!x) RADIUS += 4; // ERROR! else num= 17; cout << num << endl;
int x = 4, y = 5; bool is. Working = false; if(x> 0&& y > 0) is. Working = true; if(is. Working) x = 5; cout << x << y << endl;
int x = 4, y = 5; bool is. Working = false; if(x> 0&& y > 0) // True is. Working = true; if(is. Working) // True x = 5; cout << x << y << endl; // 55
int x = 4, y = 5; bool is. Working = false; if(x<y) if(is. Working) is. Working = false; else is. Working = true; else y = 20; cout << is. Working << endl;
int x = 4, y = 5; bool is. Working = false; if(x<y) if(is. Working) is. Working = false; else is. Working = true; else y = 20; cout << is. Working << endl; // Prints 1
int x = 4; double y = 2. 5; int yx = 3; cout << ((2*x)/3 < yx && 2 == int(y));
int x = 4; double y = 2. 5; int yx = 3; cout << ((2*x)/3 < yx && 2 == int(y)); // 8/3 < 3 && 2 == 2 // 2 < 3 && 2 ==2 // TRUE
List the logical operators in order of precedence with the operator with the highest precedence being listed first.
List the logical operators in order of precedence with the operator with the highest precedence being listed first. !, &&, ||
Provide two examples of unary operators.
Provide two examples of unary operators. ++, --, !
What is the decimal equivalent of the following binary number? 110100
What is the decimal equivalent of the following binary number? 110100 52
Operator Review Relational Operators: <, >, <=, >=, ==, != Logical Operators: !, &&, || Assignment Operator: = Shortcut Assignment Operators: +=, -=, /=, *=, %= Increment Operator: ++ Decrement Operator: -Arithmetic Operators: +, -, *, /, % Unary Operators (operator on one item): -, !, ++, -** Know when to use == vs. =