1. What does an if statement do in C++?
Correct Answer: a) It executes a block when the condition is true
Explanation:
An if statement runs its controlled statement only when its condition evaluates to true.
2. Which is the correct basic syntax of an if statement in C++?
Correct Answer: b) if (x == 1) { }
Explanation:
C++ places the condition in parentheses and does not use the keyword then.
3. When does the else part of an if statement execute?
Correct Answer: c) When the if condition is false
Explanation:
The else clause provides code that runs when the if condition evaluates to false.
4. Which of the following can directly follow an if statement in C++?
Correct Answer: d) Both else if and else
Explanation:
An if statement can be followed by zero or more else if branches and an optional else branch.
5. In C++, the condition inside an if statement is evaluated in which context?
Correct Answer: a) A Boolean context
Explanation:
The condition is contextually converted to bool, so many scalar types can be used.
6. What happens when the condition is if (0)?
Correct Answer: b) The if block is skipped
Explanation:
Zero converts to false, so the if body is not executed.
7. What happens when the condition is if (1)?
Correct Answer: c) The if block executes
Explanation:
One converts to true, so the if body is executed.
8. Which statement is true about the else part of an if statement?
Correct Answer: d) It is optional
Explanation:
An if statement may exist without an else clause.
9. In an if, else if, else chain, what happens after the first true condition is found?
Correct Answer: a) The remaining else if conditions are skipped
Explanation:
Only one branch in an if, else if, else chain is executed.
10. How many final else clauses can be associated with one if, else if chain?
Correct Answer: b) One final else clause
Explanation:
A chain may contain multiple else if branches but only one final else.
11. When are braces required around the body of an if statement?
Correct Answer: c) They are optional for a single controlled statement
Explanation:
If the body is a single statement, braces are optional, though often recommended.
12. What is true about a variable declared inside an if block?
Correct Answer: d) It is accessible only within that if block
Explanation:
Variables declared inside a block have block scope.
13. In C++, how is a dangling else resolved?
Correct Answer: a) It is attached to the nearest unmatched if
Explanation:
The else belongs to the closest if that does not already have an else.
14. If x is an int, what does if (x = 5) do?
Correct Answer: b) It assigns 5 to x and the condition is true
Explanation:
The single equals sign performs assignment, and the assignment expression yields 5, which converts to true.
15. Which operator checks equality in C++?
Correct Answer: c) ==
Explanation:
The equality operator is written as two equal signs.
16. Which operator checks inequality in C++?
Correct Answer: d) !=
Explanation:
The inequality operator compares whether two values are not equal.
17. Which of the following is a relational operator?
Correct Answer: a) <
Explanation:
The less-than operator compares two values and produces a Boolean result.
18. Which operator represents logical AND in C++?
Correct Answer: b) &&
Explanation:
The double ampersand is the logical AND operator.
19. Which operator represents logical OR in C++?
Correct Answer: c) ||
Explanation:
The double vertical bar is the logical OR operator.
20. Which operator represents logical NOT in C++?
Correct Answer: d) !
Explanation:
The exclamation mark negates a Boolean value.
21. What does short-circuit evaluation mean for the && operator?
Correct Answer: a) The right operand is not evaluated if the left operand is false
Explanation:
If the left side of && is false, the whole expression must be false, so the right side is skipped.
22. What does short-circuit evaluation mean for the || operator?
Correct Answer: b) The right operand is not evaluated if the left operand is true
Explanation:
If the left side of || is true, the whole expression is already true.
23. What is the result of the condition if (5 > 3 && 2 > 4)?
Correct Answer: c) False
Explanation:
The first comparison is true, but the second is false, so the AND expression is false.
24. What is the result of the condition if (5 > 3 || 2 > 4)?
Correct Answer: d) True
Explanation:
The first comparison is true, so the OR expression is true.
25. Which is the correct syntax of the conditional operator?
Correct Answer: a) condition ? expression1 : expression2
Explanation:
The ternary conditional operator selects the first expression when the condition is true and the second when it is false.
26. What does x = (a > b) ? a : b; assign to x?
Correct Answer: b) The larger value
Explanation:
If a is greater than b, a is selected; otherwise, b is selected.
27. What is the associativity of the conditional operator in C++?
Correct Answer: c) Right to left
Explanation:
The conditional operator groups from right to left when nested.
28. If int x = 10, what is true about if (x)?
Correct Answer: d) It is true because nonzero values convert to true
Explanation:
Any nonzero integral value converts to true in a Boolean context.
29. Which statement can execute a statement only when a condition is true?
Correct Answer: a) if
Explanation:
The if statement is the basic decision-making statement in C++.
30. What happens if a semicolon is placed directly after if (x > 5), followed by a cout statement?
Correct Answer: b) cout executes always
Explanation:
The semicolon makes the if body an empty statement, so the following statement is not controlled by the if.
31. Which is the correct syntax for an else if branch?
Correct Answer: c) else if (condition) { }
Explanation:
C++ uses the two keywords else and if together, with the condition in parentheses.
32. Which of the following is not a standard C++ control-flow keyword?
Correct Answer: d) elseif
Explanation:
C++ uses else if as two separate keywords, not elseif.
33. What is a nested if statement?
Correct Answer: a) An if statement inside another if statement
Explanation:
Nested if statements allow decisions to depend on multiple related conditions.
34. In if (condition) statement1; statement2; without braces, when does statement2 execute?
Correct Answer: b) Always
Explanation:
Only statement1 is controlled by the if statement; statement2 is outside the if body.
35. What should be used to execute multiple statements when an if condition is true?
Correct Answer: c) Braces
Explanation:
Braces create a compound statement, allowing several statements to be controlled by one if.
36. Which statement is true about an if, else if, else ladder?
Correct Answer: d) It checks conditions sequentially until one is true
Explanation:
The first true condition causes its branch to execute, and the rest are skipped.
37. What is printed by int x = 3; if (x == 3) cout << 1; else cout << 2;?
Correct Answer: a) 1
Explanation:
The condition x == 3 is true, so the if branch prints 1.
38. What is printed by int x = 4; if (x > 5) cout << 1; else cout << 2;?
Correct Answer: b) 2
Explanation:
The condition x > 5 is false, so the else branch prints 2.
39. What is printed by int x = 0; if (x) cout << 1; else cout << 2;?
Correct Answer: c) 2
Explanation:
Zero converts to false, so the else branch executes.
40. What is printed by int x = 7; if (x = 7) cout << 1; else cout << 2;?
Correct Answer: d) 1
Explanation:
The assignment expression yields 7, which converts to true.
41. Among !, &&, ||, and =, which operator has the highest precedence?
Correct Answer: a) !
Explanation:
Logical NOT has higher precedence than logical AND, logical OR, and assignment.
42. Which operator has higher precedence than &&?
Correct Answer: b) ==
Explanation:
Equality comparison is evaluated before logical AND.
43. When is if (x == 1 || x == 2) true?
Correct Answer: c) When x is either 1 or 2
Explanation:
The OR operator makes the condition true if either comparison is true.
44. When is if (x > 0 && x < 10) true?
Correct Answer: d) When x is greater than 0 and less than 10
Explanation:
Both comparisons must be true because they are joined with AND.
45. Which condition checks that x is not equal to 5?
Correct Answer: a) x != 5
Explanation:
The inequality operator != tests whether two values are different.
46. Which of the following is a valid Boolean expression in C++?
Correct Answer: b) x % 2 == 0
Explanation:
The modulo and equality operators combine to form a valid expression that evaluates to true or false.
47. What does if (x % 2 == 0) test?
Correct Answer: c) Whether x is even
Explanation:
An even integer has remainder 0 when divided by 2.
48. What is the result of bool(10 < 20)?
Correct Answer: d) true
Explanation:
Ten is less than twenty, so the comparison evaluates to true.
49. Which integer value converts to false in C++?
Correct Answer: a) 0
Explanation:
Zero is the integer value that converts to false.
50. Which pointer value converts to false in C++?
Correct Answer: b) A null pointer
Explanation:
A null pointer converts to false, while a non-null pointer converts to true.
51. What does if (ptr) check when ptr is a pointer?
Correct Answer: c) Whether ptr is non-null
Explanation:
A pointer in a Boolean context is true when it is not null.
52. Which statement is true about an if, else if ladder?
Correct Answer: d) It can contain multiple else if branches
Explanation:
C++ allows many else if branches before an optional final else.
53. What is printed by int a = 5; if (a > 1) cout << 10; cout << 20;?
Correct Answer: a) 1020
Explanation:
The if condition is true, so 10 is printed, and the second cout is outside the if, so 20 is also printed.
54. What is printed by int a = 5; if (a > 10) cout << 10; cout << 20;?
Correct Answer: b) 20
Explanation:
The if condition is false, so only the statement after the if executes.
55. What is printed by int a = 5; if (a > 10) { cout << 10; } else { cout << 20; }?
Correct Answer: c) 20
Explanation:
The condition is false, so the else block executes.
56. What is printed by int a = 5; if (a == 5) { cout << 10; } else if (a > 0) { cout << 20; }?
Correct Answer: d) 10
Explanation:
The first condition is true, so its branch executes and the else if is skipped.
57. What is printed by int a = 5; if (a == 6) { cout << 10; } else if (a > 0) { cout << 20; }?
Correct Answer: a) 20
Explanation:
The first condition is false, but the else if condition is true.
58. What is printed by int a = 5; if (a == 6) cout << 10; else if (a == 7) cout << 20; else cout << 30;?
Correct Answer: b) 30
Explanation:
Neither the if nor the else if condition is true, so the final else executes.
59. What is printed by int a = 5; if (a > 0) if (a > 3) cout << 1; else cout << 2;?
Correct Answer: c) 1
Explanation:
Both conditions are true, so the inner if branch prints 1.
60. What is printed by int a = 5; if (a > 0) if (a > 10) cout << 1; else cout << 2;?
Correct Answer: d) 2
Explanation:
The outer condition is true, but the inner condition is false, so the else attached to the inner if executes.
61. What can be used to avoid dangling else ambiguity?
Correct Answer: a) Braces
Explanation:
Braces make the intended grouping of if and else explicit.
62. Which statement is true about the expression inside if (expression)?
Correct Answer: b) The expression is contextually converted to bool
Explanation:
C++ allows many scalar expressions in if conditions by converting them to Boolean values.
63. Which is a valid if statement in C++?
Correct Answer: c) if (x > 0) cout << 1;
Explanation:
The condition must be in parentheses, and no colon or then keyword is used.
64. Which of the following is invalid C++ syntax?
Correct Answer: d) if (x) then cout << x;
Explanation:
C++ does not use the keyword then in if statements.
65. What does the break statement do?
Correct Answer: a) It exits a loop or switch
Explanation:
break terminates the nearest enclosing loop or switch statement.
66. What does the continue statement do?
Correct Answer: b) It skips to the next loop iteration
Explanation:
continue skips the remaining loop body and proceeds to the next iteration.
67. Which statement is true about the switch statement?
Correct Answer: c) It can handle integral constant case labels
Explanation:
switch works with integral or enumeration values and constant case labels.
68. What happens in a switch statement when a matching case has no break?
Correct Answer: d) Execution falls through to the next case
Explanation:
Without break, control continues into subsequent case labels.
69. Which type cannot be used directly as the controlling expression of a switch statement?
Correct Answer: a) double
Explanation:
switch requires an integral or enumeration type, not a floating-point type.
70. Which case label is valid in C++?
Correct Answer: b) case 5:
Explanation:
Case labels must be integral constant expressions.
71. What is printed by switch (1) { case 1: cout << 1; break; case 2: cout << 2; }?
Correct Answer: c) 1
Explanation:
Case 1 matches, prints 1, and break prevents fallthrough.
72. What is printed by switch (1) { case 1: cout << 1; case 2: cout << 2; }?
Correct Answer: d) 12
Explanation:
There is no break, so execution falls through from case 1 to case 2.
73. Which statement is true about the default label in a switch statement?
Correct Answer: a) It is optional
Explanation:
A switch statement may omit the default label.
74. Which statement is true about case labels in a switch statement?
Correct Answer: b) They must be constant expressions
Explanation:
Case labels must be unique integral constant expressions.
75. Which loop executes its body at least once before checking the condition?
Correct Answer: c) do-while
Explanation:
A do-while loop checks its condition after executing the body.
76. Which loop checks its condition before executing the loop body?
Correct Answer: d) while
Explanation:
A while loop evaluates its condition before each iteration.
77. What is printed by for (int i = 0; i < 3; ++i) cout << i;?
Correct Answer: a) 012
Explanation:
The loop prints 0, then 1, then 2, and stops before i becomes 3.
78. What is printed by while (false) cout << 1;?
Correct Answer: b) No output
Explanation:
The condition is false initially, so the body never executes.
79. What is printed by do { cout << 1; } while (false);?
Correct Answer: c) 1
Explanation:
The do-while body executes once before the false condition is checked.
80. Which statement creates an infinite loop?
Correct Answer: d) while (true) { }
Explanation:
The condition is always true, so the loop never terminates by itself.
81. Which statement is commonly used to test multiple discrete values?
Correct Answer: a) switch
Explanation:
switch selects among multiple constant case labels.
82. Which construct is usually better for testing ranges of values?
Correct Answer: b) if-else
Explanation:
if-else can use relational expressions such as greater than and less than.
83. If x is an int, what is the result of if (x = 0)?
Correct Answer: c) The condition is false
Explanation:
The assignment expression yields 0, which converts to false.
84. Which symbols create a compound statement or block in C++?
Correct Answer: d) Braces
Explanation:
A block is written with an opening brace and a closing brace.
85. Which statement is true about an if statement without else?
Correct Answer: a) The program continues after the if statement
Explanation:
An if statement without else simply skips its body when the condition is false.
86. Which statement is true about the conditional operator?
Correct Answer: b) It can select one of two expressions
Explanation:
The ternary operator chooses between two expressions based on a condition.
87. What is the value of y after int x = 10; int y = (x > 5) ? 1 : 2;?
Correct Answer: c) 1
Explanation:
The condition x > 5 is true, so the first value is selected.
88. What is the value of y after int x = 1; int y = (x > 5) ? 1 : 2;?
Correct Answer: d) 2
Explanation:
The condition x > 5 is false, so the second value is selected.
89. What is printed by int x = 5; cout << ((x > 3) ? 10 : 20);?
Correct Answer: a) 10
Explanation:
The condition x > 3 is true, so 10 is selected.
90. What is printed by int x = 2; cout << ((x > 3) ? 10 : 20);?
Correct Answer: b) 20
Explanation:
The condition x > 3 is false, so 20 is selected.
91. Which if statement is equivalent to (a > b) ? x : y; when assigning to result?
Correct Answer: c) if (a > b) result = x; else result = y;
Explanation:
The ternary expression assigns x when the condition is true and y when it is false.
92. What happens with int x = 0; if (++x) cout << x;?
Correct Answer: d) It prints 1
Explanation:
Prefix increment changes x to 1, and 1 converts to true.
93. What is printed by int x = 0; if (x++) cout << 1; else cout << 2;?
Correct Answer: a) 2
Explanation:
Postfix increment yields the old value 0, so the condition is false.
94. What is printed by int x = 1; if (--x) cout << 1; else cout << 2;?
Correct Answer: b) 2
Explanation:
Prefix decrement changes x to 0, and 0 converts to false.
95. What is printed by int x = 1; if (x--) cout << 1; else cout << 2;?
Correct Answer: c) 1
Explanation:
Postfix decrement yields the old value 1, so the condition is true.
96. Which statement is true about using assignment inside an if condition?
Correct Answer: d) It may be legal but is often unintended
Explanation:
Assignment in a condition can compile, but programmers often meant to use equality comparison.
97. Which condition correctly tests whether x is between 1 and 10 inclusive?
Correct Answer: a) x >= 1 && x <= 10
Explanation:
Both comparisons must be written separately and joined with AND.
98. Why is if (1 <= x <= 10) usually wrong in C++?
Correct Answer: b) It does not test the range as intended
Explanation:
C++ evaluates 1 <= x first, producing a Boolean value, then compares that value with 10.
99. What happens with if (x == 5); { cout << 1; } when x is 5?
Correct Answer: c) It prints 1 regardless of the condition
Explanation:
The semicolon makes the if body empty, and the following block is independent.
100. What best describes control flow in a program?
Correct Answer: d) The order in which statements are executed
Explanation:
Control flow determines the sequence in which program statements run.









