Sequence Control in C ++ Programming MCQ Questions and Answers

1. What is the output of this code?
int main(){
int a = 5;
if(a > 3)
if(a < 10) cout << “X”;
else cout << “Y”;
else cout << “Z”;
}
A) X
B) Y
C) Z
D) Compiler error
Answer: A

2. Which statement is true about the continue statement inside a for loop?
A) It terminates the loop completely.
B) It causes program to exit the current function.
C) It skips the remaining statements in the current iteration and proceeds to the next iteration.
D) It restarts the loop from the beginning of program.
Answer: C

3. Given:
int i = 0;
while(i++ < 3) cout << i << ” “;
What is printed?
A) 0 1 2
B) 1 2 3 4
C) 1 2 3
D) 2 3 4
Answer: C

4. Which of these is NOT a sequence control construct in C++?
A) if-else
B) switch
C) for
D) namespace
Answer: D

5. What does the ?: (ternary) operator return in this expression: int x = (5>3) ? 10 : 20;?
A) 5
B) 10
C) 3
D) 20
Answer: B

6. Which of the following switch behaviors is correct in C++?
A) switch expression must be a double.
B) case labels can be variables.
C) case labels must be constant expressions.
D) switch automatically breaks after each case.
Answer: C

7. What will the following print?
for(int i=0;i<3;i++){
for(int j=0;j<2;j++) if(i==1) break;
cout<<i<<” “;
}
A) 0 1 2
B) 0 1 2
C) 0 2
D) 0 1
Answer: B

8. Which loop will always execute its body at least once?
A) for
B) while
C) do-while
D) None of these
Answer: C

9. What is the value of x after:
int x = 1;
x = x++ + ++x;
Assume well-defined evaluation order for this expression in modern C++ compilers.
A) 3
B) 4
C) Undefined behavior
D) 2
Answer: C

10. The break statement in a nested loop affects which loop?
A) Outermost loop only
B) Nearest enclosing loop
C) All loops in the program
D) Function in which loops reside
Answer: B

11. Which of the following is true about if without else?
A) It always executes else implicitly.
B) It executes alternate branch when condition fails.
C) It simply skips the controlled statement when condition is false.
D) It causes compilation error.
Answer: C

12. What does this code print?
int main(){
for(int i=0;i<2;i++)
cout<<i;
cout<<i;
}
A) 001
B) 01
C) Compiler error (i out of scope)
D) 012
Answer: C

13. Which statement about goto is correct?
A) It cannot jump out of the current function.
B) It can jump to any label in the same function.
C) It is the preferred control structure in modern C++.
D) It is illegal in C++.
Answer: B

14. What is printed?
int a=0;
if(a==0) cout<<“A\n”;
else if(a==1) cout<<“B\n”;
else cout<<“C\n”;
A) B
B) C
C) A
D) Compiler error
Answer: C

15. Which of these expressions is evaluated first in a + b * c?
A) a + b
B) b * c
C) a + c
D) Compiler decides at runtime
Answer: B

16. In C++, the switch expression must be of which type?
A) Floating point only
B) Integral or enumeration type
C) Pointer only
D) Class type only
Answer: B

17. What is the output?
int main(){
int x = 0;
do {} while(x);
cout << “Done”;
}
A) Nothing
B) Runtime error
C) Done
D) Infinite loop
Answer: C

18. Which is true about else if ladder?
A) All conditions are evaluated every time.
B) Evaluation stops at first true condition.
C) else if is a separate keyword in C++.
D) It requires break statements.
Answer: B

19. Output of:
int main(){
for(int i=0;i<5;i++)
if(i%2==0) continue;
else cout<<i;
}
A) 1 3
B) 13
C) 024
D) 0 2 4
Answer: B

20. Which statement about switch fall-through is correct?
A) There is no fall-through in C++.
B) Control flows into the next case unless break is used.
C) break is mandatory after each case.
D) case cannot be adjacent.
Answer: B

21. What does return do inside a function?
A) Terminates current loop only
B) Terminates function and returns control to caller (optionally with value).
C) Restarts function execution
D) Only allowed in main function
Answer: B

22. What is the result of int a = (1,2,3);?
A) a becomes 1
B) a becomes 2
C) a becomes 3
D) Compilation error
Answer: C

23. Which operator has the highest precedence among these?
A) + (addition)
B) == (equality)
C) && (logical and)
D) ++ (increment, postfix or prefix)
Answer: D

24. Behavior of this code:
int x=0;
if(false) cout<<“A”; else cout<<“B”;
A) A
B) B
C) Nothing
D) Compiler error
Answer: B

25. Which of following is a sequence point (pre-C++11 terminology) or ensures sequencing?
A) Comma operator in function arguments
B) Assignment with = between two unrelated variables
C) Logical && between expressions (left evaluated before right if needed)
D) Post-increment inside function call parameter with another post-increment (undefined)
Answer: C

26. What will print?
int main(){
switch(2){
case 1: cout<<“A”; break;
case 2: cout<<“B”;
default: cout<<“C”;
}
}
A) A
B) BC
C) B
D) Compiler error
Answer: B

27. Which statement about while condition evaluation is true?
A) Condition is evaluated after loop body.
B) Condition is evaluated before each iteration.
C) Condition is evaluated only once.
D) Condition cannot be a function call.
Answer: B

28. For for(initial; condition; increment) which part executes only once?
A) condition
B) increment
C) initial
D) all parts execute every time
Answer: C

29. What is printed?
int i=0;
for(; i<3; )
cout<<i++;
cout<<i;
A) 0123
B) 0 1 2 3 (without spaces: 0123)
C) 012
D) 123
Answer: A

30. Which is correct about switch labels?
A) They can be duplicated.
B) They must be unique constant expressions.
C) They accept ranges natively.
D) They can be floats.
Answer: B

31. What does break do in a switch?
A) Skip to next case
B) Exit the switch block
C) Exit function
D) Continue to next iteration
Answer: B

32. Which of the following is true about do { } while(cond);?
A) Executes zero times if cond is false initially.
B) Executes body once before testing condition.
C) Equivalent to while always.
D) Requires break to end.
Answer: B

33. Output of:
int main(){
int x=5;
cout << (x>0 ? x : -x);
}
A) -5
B) 0
C) 5
D) Compiler error
Answer: C

34. Which statement best describes short-circuit evaluation?
A) Both operands always evaluated.
B) Right operand may not be evaluated if left determines result (for &&, ||).
C) Only used in bitwise operators.
D) It is a runtime error.
Answer: B

35. Which is true about nested if statements without braces?
A) Indentation determines nesting.
B) Only single statements after each if are controlled.
C) Multiple statements are controlled automatically.
D) Braces are required.
Answer: B

36. What is printed?
int main(){
int n=3;
switch(n){
case 1: cout<<1; break;
case 2: cout<<2; break;
default: cout<<3;
}
}
A) 1
B) 2
C) 3
D) Compiler error
Answer: C

37. What happens when you break inside inner loop?
A) Terminates outer loop too.
B) Terminates only the current (inner) loop.
C) Restarts inner loop.
D) Exits the function.
Answer: B

38. Which operator can be used to combine statements while guaranteeing left-to-right evaluation when used as an operator?
A) +
B) &&
C) ||
D) Comma operator (,)
Answer: D

39. What is the value of i after:
int i=0;
i = ++i + ++i;
A) 2
B) 3
C) Undefined behavior
D) 4
Answer: C

40. Which is correct regarding switch and case with multiple labels?
A) case 1,2: is valid.
B) You must write separate case labels (case 1: case 2:) to have same block.
C) case accepts ranges natively.
D) case can be expression evaluated at runtime.
Answer: B

41. What does this loop print?
for(int i=0;i<3;i++)
cout<<i;
A) 0 1 2 with spaces
B) 012
C) 123
D) 0 1 2 (separate tokens)
Answer: B

42. What is the output?
int main(){
int x = 10;
if(x %= 5) cout<<“A”; else cout<<“B”;
}
A) A
B) B
C) Compiler error
D) A and then B
Answer: B

43. What will this print?
int main(){
int i=1;
if(i==1) if(i<2) cout<<“A”; else cout<<“B”;
else cout<<“C”;
}
A) B
B) C
C) A
D) Compiler error
Answer: C

44. Which of the following is true about for(;;)?
A) Syntax error
B) Runs zero times
C) Infinite loop (unless broken)
D) Equivalent to for(0;0;0)
Answer: C

45. Which choice about switch and enum is correct?
A) switch cannot use enum.
B) switch can switch on enum values.
C) Enum values must be strings for switch.
D) switch converts enums to float first.
Answer: B

46. What does the default label in switch mean?
A) It executes always.
B) It executes when no case matches.
C) It is executed before any case.
D) It is required in every switch.
Answer: B

47. What about this code?
int x = 2;
if(x==1);
cout<<“Hi”;
A) Prints nothing
B) Prints Hi only if x==1
C) Always prints Hi (because semicolon ends if)
D) Compiler error
Answer: C

48. Which construct best represents decision-making in sequence control?
A) loops
B) functions
C) if-else and switch
D) typedefs
Answer: C

49. What will be the output?
int main(){
for(int i=0;i<2;i++){
for(int j=0;j<2;j++) if(i==0) break;
cout<<i;
}
}
A) 00
B) 01
C) 10
D) 10
Answer: B

50. In C++, which of these guarantees left-to-right evaluation of arguments?
A) The compiler always chooses order.
B) Function call arguments evaluation order is unspecified until C++17; from C++17 it is left-to-right.
C) It is right-to-left by standard.
D) Evaluation order is defined by OS.
Answer: B

51. Which statement about else is true?
A) It can appear without matching if.
B) It must be associated with the nearest unmatched if.
C) It can be used standalone.
D) It must always be followed by if.
Answer: B

52. What is the output?
int main(){
int x=1;
if(x) cout<<“T”; else cout<<“F”;
if(!x) cout<<“!T”;
}
A) TF
B) T
C) !T
D) T!T
Answer: B

53. Which is correct about the break in switch?
A) It throws exception.
B) It prevents fall-through.
C) It is optional but recommended for all case labels.
D) Both B and C.
Answer: D

54. Which of the following is a valid for header?
A) for(int i=0; i<10); i++ {}
B) for(int i=0, j=0; i<10; ++i, ++j)
C) for(int i=0 i<10; ++i)
D) for(i in 0..9)
Answer: B

55. What prints?
int main(){
int a=3;
switch(a){
default: cout<<“D”;
case 3: cout<<“T”;
}
}
A) T
B) D
C) DT
D) TD
Answer: C

56. Which operator is used to test multiple conditions combined and stop evaluating as soon as result is known?
A) & (bitwise)
B) | (bitwise)
C) && and || (logical) — short-circuiting)
D) ^ (xor)
Answer: C

57. What is output?
int main(){
int i=0;
while(i++<0) cout<<“A”;
cout<<“B”;
}
A) A B
B) B
C) AB (without space)
D) Infinite loop
Answer: B

58. Which is true for switch with no case match but default present?
A) Nothing executes.
B) default executes.
C) Compiler error.
D) Behavior undefined.
Answer: B

59. What is the result?
int main(){
int x=4;
cout << (x&1 ? “Odd”:”Even”);
}
A) Odd
B) Even
C) 1
D) Compiler error
Answer: B

60. How many times does the body execute?
int i=0;
while(i<3){ cout<<i; ++i; }
A) 0
B) 2
C) 3
D) 4
Answer: C

61. Which is correct about using braces {}?
A) They are optional around multi-line if bodies.
B) They group multiple statements into a single block to be controlled by constructs.
C) They change precedence of expressions.
D) They are only for functions.
Answer: B

62. Which of the following leads to undefined behavior?
A) Modifying a variable twice between sequence points (pre-C++11).
B) Modifying and reading same scalar without sequencing (e.g., i = i++)
C) Using break in switch.
D) Using continue in loops.
Answer: B

63. Output:
int main(){
int a=1,b=2;
if(a==1) if(b==2) cout<<“Yes”; else cout<<“No”;
}
A) No
B) Yes
C) Compiler error
D) Nothing
Answer: B

64. What happens if break omitted in a case?
A) Compiler inserts one.
B) Execution falls through to next case.
C) Program crashes.
D) Function returns.
Answer: B

65. Which statement about for loop variables declared inside header is true?
A) They are accessible after loop.
B) They have scope limited to loop body.
C) They are global.
D) They persist across function calls.
Answer: B

66. Which is correct about if (x=0)?
A) Compares x to 0.
B) Assigns 0 to x then tests (false).
C) Causes compilation error.
D) Throws runtime exception.
Answer: B

67. What is printed?
int main(){
int k = 0;
for(int i=0;i<3;i++)
k += (i==1) ? 10 : 0;
cout<<k;
}
A) 0
B) 10
C) 10
D) 30
Answer: C

68. Which of these ensures a loop will eventually terminate (in general)?
A) Using continue
B) A condition that becomes false after finite iterations
C) Using goto only
D) Including break unconditionally
Answer: B

69. What prints?
int main(){
int x=2;
switch(x){
case 1: cout<<1;
case 2: cout<<2; break;
case 3: cout<<3;
}
}
A) 123
B) 2
C) 23
D) 12
Answer: B

70. Which of these causes immediate exit from a function regardless of loops?
A) break
B) continue
C) return
D) goto label in other function
Answer: C

71. In if (a && b()), when is b() called?
A) Always.
B) Never.
C) Only if a is true (short-circuit).
D) Only if a is false.
Answer: C

72. What is the output?
int main(){
for(int i=0;i<2;i++)
for(int j=0;j<2;j++)
if(i+j==1) cout<<i<<j;
}
A) 01 10
B) 01 10 (without spaces: 0110)
C) 00 11
D) 10 01
Answer: B

73. Which is NOT allowed in a switch case label?
A) Constant literal
B) Enum constant
C) Variable
D) constexpr value
Answer: C

74. What is printed?
int main(){
int i=0;
if(i) cout<<“A”; else cout<<“B”;
}
A) A
B) B
C) Nothing
D) Compiler error
Answer: B

75. Which of these is a structured way to choose among many alternatives?
A) Ternary only
B) While loop
C) switch statement
D) goto chain
Answer: C

76. What will for(int i=0;i<3;++i) cout<<i<<“,”; produce?
A) 0,1,2,
B) 0,1,2,
C) 012,
D) ,0,1,2
Answer: B

77. Which is true for if (condition) statement; when statement is a declaration?
A) Declaration must be in braces.
B) Declarations are allowed but have limited scope; using braces is safer and clearer.
C) Compiler forbids declarations in if.
D) Declaration always executes even if condition false.
Answer: B

78. Output:
int main(){
int x = 1;
cout << (x==1 ? x : ++x);
}
A) 1
B) 2
C) 1
D) Undefined
Answer: C

79. Which of these controls can be used to create an infinite loop?
A) for(;;)
B) while(true)
C) do {} while(true)
D) All of the above
Answer: D

80. What is the effect of continue in a do-while loop?
A) Goes to function return.
B) Jumps to condition test and then possibly next iteration.
C) Exits the loop.
D) Has no effect.
Answer: B

81. Which is correct for the switch fall-through optimization?
A) Modern compilers always eliminate fall-through.
B) Fall-through occurs unless break or other control transfer prevents it.
C) Fall-through is illegal in standards-compliant code.
D) return in a case still triggers fall-through.
Answer: B

82. What prints?
int main(){
int n=0;
if(n++ == 0) cout<<“A”;
if(++n == 2) cout<<“B”;
}
A) A
B) B
C) AB
D) None
Answer: C

83. Which is true about loops and nested scope?
A) Inner loop cannot access outer loop variables.
B) Inner loop can access variables with appropriate scope from outer loop.
C) Variables declared in inner loop exist after outer loop completes.
D) Nested loops cause automatic copying of variables.
Answer: B

84. What is the output?
int main(){
int x=5;
cout << (x>10 ? 1 : x>0 ? 2 : 3);
}
A) 1
B) 3
C) 2
D) Compiler error
Answer: C

85. Which is true about switch with string literals in standard C++?
A) switch accepts std::string.
B) switch cannot directly switch on strings; needs integral or enum.
C) case “a”: is valid.
D) switch maps strings to integers automatically.
Answer: B

86. What will be the output?
int main(){
int i=0;
for(; i<1; ++i) ;
cout<<i;
}
A) 0
B) 1
C) Compiler error
D) 2
Answer: B

87. Which of the following about if-else indentation is true?
A) Indentation is mandatory for correctness.
B) Indentation is for readability; braces define actual grouping.
C) Compiler uses indentation to parse.
D) No braces allowed if indented.
Answer: B

88. Which statement is true about evaluation of a || b()?
A) b() always called.
B) b() called only if a is false.
C) a ignored.
D) Both evaluated in parallel.
Answer: B

89. What does this print?
int main(){
int a=2;
switch(a){
case 1: cout<<1; break;
default: cout<<0; break;
case 2: cout<<2;
}
}
A) 1
B) 0
C) 2
D) 02
Answer: C

90. Which of these will not change loop variable automatically?
A) for loop increment expression
B) statements inside loop body
C) switch labels inside loop (they don’t change variable by themselves)
D) continue with modification
Answer: C

91. Which is true about if (true) ; else {}?
A) Executes else.
B) The semicolon forms an empty if body; since the condition is true, else is skipped.
C) Compiler error always.
D) Both branches executed.
Answer: B

92. What prints?
int main(){
int i=0;
if(i=0) cout<<“A”; else cout<<“B”;
}
A) A
B) B
C) Compiler error
D) Depends on compiler
Answer: B

93. Which is true about switch with long long type?
A) Not allowed.
B) Allowed if integral; long long is integral so allowed.
C) Only int allowed.
D) Only enum allowed.
Answer: B

94. What is the output?
int main(){
for(int i=0;i<3;i++)
if(i==1) { cout<<“One”; break; }
cout<<“Done”;
}
A) OneDone
B) OneDone
C) DoneOne
D) Compiler error
Answer: B

95. Which statement about else after switch is true?
A) else can follow switch.
B) else cannot directly follow switch (since switch is not an if).
C) It is standard usage.
D) It will cause fall-through.
Answer: B

96. What prints?
int main(){
int x=0;
if(x) cout<<“A”;
else if(x==0) cout<<“B”;
else cout<<“C”;
}
A) A
B) B
C) C
D) Nothing
Answer: B

97. Which is true about break in do-while?
A) Not allowed.
B) Allowed and exits loop.
C) Only allowed with label.
D) Causes undefined behaviour.
Answer: B

98. What is printed?
int main(){
int a=0,b=1;
if(a && b) cout<<“X”;
else cout<<“Y”;
}
A) X
B) Y
C) Nothing
D) Compiler error
Answer: B

99. Which best describes sequence control in C++?
A) Management of memory allocation only
B) Management of types only
C) Control of execution order using constructs like if, switch, loops, goto, and conditional operators.
D) Handling templates
Answer: C

100. What is the output?
int main(){
int x=1;
switch(x){
case 1: cout<<1;
case 2: cout<<2;
default: cout<<3;
}
}
A) 1
B) 12
C) 123
D) 23
Answer: C