if, if-else, nested if — C++ MCQs 20 Score: 0 Attempted: 0/20 1. What will be the output of the following code?int x = 10;if (x > 5)cout << "Hello";elsecout << "World"; (A) Hello (B) World (C) Error (D) Nothing 2. What will the following code print?int x = 5;if (x == 5)cout << "Yes"; (A) Yes (B) No (C) Error (D) Nothing 3. What will be the output of this code?int a = 3;if (a > 5)cout << "Greater";elsecout << "Smaller"; (A) Greater (B) Smaller (C) 0 (D) Error 4. What will this code output?int x = 7;if (x < 5)cout << "A";else if (x == 7)cout << "B";elsecout << "C"; (A) A (B) Error (C) C (D) B 5. Identify the error in the following code:int x = 5if (x > 0)cout << "Positive"; (A) Missing semicolon after if (B) Missing semicolon after variable declaration (C) Wrong if syntax (D) No error 6. What is the output?int num = 10;if (num % 2 == 0)cout << "Even";elsecout << "Odd"; (A) Odd (B) Error (C) Even (D) 0 7. What will the following code display?int x = 2, y = 3;if (x > y)cout << "X is greater";elsecout << "Y is greater"; (A) X is greater (B) Y is greater (C) Error (D) Nothing 8. What will be the output of this nested if code?int a = 4, b = 8;if (a > 5)if (b > 5)cout << "Both";elsecout << "Only a";elsecout << "None"; (A) Both (B) Only a (C) None (D) Error 9. What will the code print?int x = 0;if (x)cout << "True";elsecout << "False"; (A) True (B) 0 (C) Error (D) False 10. Identify the output:int x = 10;if (x = 5)cout << "Yes";elsecout << "No"; (A) Yes (B) No (C) Error (D) Nothing 11. What is the output of this code?int x = 3;if (x > 0 && x < 5)cout << "Inside";elsecout << "Outside"; (A) Inside (B) Outside (C) Error (D) Nothing 12. What happens when this code runs?int x = 4;if (x > 5)cout << "A";else if (x > 3)cout << "B";elsecout << "C"; (A) A (B) B (C) C (D) Error 13. Which statement is true about this code?int x = 7;if (x > 5)if (x < 10)cout << "Yes"; (A) Yes (B) No (C) Error (D) Nothing 14. What will this code print?int x = 2;if (x == 1)cout << "One";else if (x == 2)cout << "Two";elsecout << "Other"; (A) One (B) Other (C) Two (D) Error 15. Identify the error:if (x > 5);cout << "Hello"; (A) Extra semicolon after if (B) Missing braces (C) Syntax is correct (D) Nothing 16. Output of the following code:int x = 5;if (x != 5)cout << "No";elsecout << "Yes"; (A) Yes (B) No (C) Error (D) Nothing 17. What will the following code output?int a = 10, b = 20;if (a > b)cout << "A";else if (a < b)cout << "B";elsecout << "C"; (A) A (B) B (C) C (D) Error 18. What will be printed?int x = -1;if (x > 0)cout << "Positive";else if (x < 0)cout << "Negative";elsecout << "Zero"; (A) Positive (B) Error (C) Zero (D) Negative 19. What is the output?int x = 5;if (x > 2)if (x < 10)cout << "Inside";elsecout << "Outside"; (A) Inside (B) Outside (C) Error (D) Nothing 20. What will this code print?int x = 0;if (x == 0)cout << "Zero";elsecout << "Non-zero"; (A) Zero (B) Non-zero (C) Error (D) Nothing Related Posts:Nested structures — C++ MCQs3 Level Nested for loop in C++ (C Plus Plus)Nested For Loop including 3 loops in C++ (C Plus Plus)Nested Elements in HTMLNested Do while Loop with 4 Levels4 Level Nested Do while Loop in Javascript