Control Statements in C ++ Programming MCQ Questions and Answers

1. Which of the following statements in C++ is used to exit from a loop immediately?
A) continue
B) goto
C) break
D) exit
Answer: C) break

2. The continue statement in C++ causes the program to:
A) Exit from the current loop
B) Terminate the program
C) Skip the rest of the loop body and start the next iteration
D) Skip the remaining statements in the loop and start next iteration
Answer: D) Skip the remaining statements in the loop and start next iteration

3. What is the output of the following code?
for(int i=0; i<5; i++){
if(i==3) break;
cout << i << ” “;
}
A) 0 1 2 3 4
B) 0 1 2
C) 1 2 3
D) 0 1 2 3
Answer: B) 0 1 2

4. The if statement in C++ is used to:
A) Loop through a block of code
B) Make a decision based on a condition
C) Handle exceptions
D) Terminate execution
Answer: B) Make a decision based on a condition

5. Which of the following is a valid syntax of the if-else statement in C++?
A) if condition then statement else statement
B) if(condition) statement; else statement;
C) if(condition): statement else: statement
D) if condition: statement otherwise statement
Answer: B) if(condition) statement; else statement;

6. What will be the output of the code below?
int x=5;
if(x>10)
cout<<“A”;
else
cout<<“B”;
A) A
B) B
C) AB
D) None
Answer: B) B

7. The switch statement in C++ is used for:
A) Multiple selection control
B) Sequential execution
C) Repetition of statements
D) Conditional compilation
Answer: A) Multiple selection control

8. The default case in a switch statement:
A) Must always be written first
B) Executes when no matching case is found
C) Executes only if break is used
D) Is mandatory in every switch
Answer: B) Executes when no matching case is found

9. In C++, the goto statement:
A) Transfers control unconditionally to a labeled statement
B) Skips one iteration
C) Exits from loop
D) Restarts program
Answer: A) Transfers control unconditionally to a labeled statement

10. What is the output of this code?
int x=2;
switch(x){
case 1: cout<<“One”; break;
case 2: cout<<“Two”;
case 3: cout<<“Three”; break;
}
A) One
B) TwoThree
C) Two
D) Three
Answer: B) TwoThree

11. Which of these statements correctly defines a nested if statement?
A) if(if(condition))
B) if(condition1){ if(condition2){ statement; } }
C) if(condition1): if(condition2): statement
D) if(condition1) and if(condition2)
Answer: B) if(condition1){ if(condition2){ statement; } }

12. Which of the following loops checks the condition after executing the loop body?
A) for
B) do-while
C) while
D) if
Answer: B) do-while

13. The expression inside the while loop parentheses must be:
A) String
B) Integer
C) Boolean (true/false)
D) Character
Answer: C) Boolean (true/false)

14. Which of the following statements about the for loop is correct?
A) Initialization is optional
B) Condition is optional
C) Increment is optional
D) All of the above
Answer: D) All of the above

15. What will happen if the condition in a for loop is always true?
A) Loop will execute once
B) Program will terminate
C) Loop will become infinite
D) Compile-time error
Answer: C) Loop will become infinite

16. In which situation would you prefer a while loop over a for loop?
A) When number of iterations is known
B) When initializing multiple variables
C) When number of iterations is not known
D) When no condition is required
Answer: C) When number of iterations is not known

17. Which statement immediately transfers control to the next iteration of a loop?
A) break
B) return
C) continue
D) skip
Answer: C) continue

18. What is the output of this code?
int i=0;
while(i<3){
cout<<i;
i++;
}
A) 012
B) 123
C) 01
D) Infinite loop
Answer: A) 012

19. Which of the following statements correctly describes exit(0);?
A) Breaks only from loops
B) Terminates the entire program successfully
C) Jumps to main function
D) Ends only the current block
Answer: B) Terminates the entire program successfully

20. What will be the output of the following code?
for(int i=1; i<=3; i++){
for(int j=1; j<=2; j++){
if(i==2) continue;
cout<<i<<j<<” “;
}
}
A) 11 12 21 22 31 32
B) 11 12 31 32
C) 11 31
D) 12 32
Answer: B) 11 12 31 32

21. What is the output of the following code?
int x = 10;
if(x = 5)
cout << “True”;
else
cout << “False”;
A) True
B) False
C) Error
D) No output
Answer: A) True

22. Which control structure is best suited for menu-driven programs?
A) if-else ladder
B) switch
C) nested if
D) while loop
Answer: B) switch

23. What will be the output of this code?
int i=1;
while(i<=3)
{
cout<<i<<” “;
i++;
}
A) 1 2 3
B) 1 2
C) 0 1 2 3
D) Infinite loop
Answer: A) 1 2 3

24. What is the result of using break inside nested loops?
A) It breaks only the innermost loop
B) Breaks all loops
C) Restarts outer loop
D) Terminates program
Answer: A) It breaks only the innermost loop

25. What is the output of the following code?
int i=0;
do{
cout<<i<<” “;
i++;
}while(i<3);
A) 0 1
B) 0 1 2
C) 1 2 3
D) 1 2
Answer: B) 0 1 2

26. What happens if there is no break statement in a switch case?
A) Control exits automatically
B) Only current case executes
C) Control falls through to the next case(s)
D) Compiler error
Answer: C) Control falls through to the next case(s)

27. Which of the following keywords is not a loop control statement in C++?
A) continue
B) break
C) stop
D) goto
Answer: C) stop

28. Which control statement allows skipping execution of the rest of the loop body?
A) break
B) continue
C) return
D) exit
Answer: B) continue

29. Which of the following statements about nested switch is correct?
A) It is not allowed
B) It is allowed, and inner switch must have different variable
C) Only one case is permitted in nested switch
D) It causes runtime error
Answer: B) It is allowed, and inner switch must have different variable

30. What is the main difference between while and do-while loops?
A) while loop executes faster
B) while checks condition before, do-while after the loop body
C) do-while cannot use break
D) while can’t use continue
Answer: B) while checks condition before, do-while after the loop body

31. What is the output of this code?
for(int i=0; i<2; i++){
for(int j=0; j<3; j++){
if(j==1) break;
cout<<i<<j<<” “;
}
}
A) 00 10
B) 00 01 10 11
C) 00 01 02
D) 10 11 12
Answer: A) 00 10

32. What will be printed by this code?
int i=5;
if(i>0)
if(i>10)
cout<<“A”;
else
cout<<“B”;
A) A
B) B
C) AB
D) None
Answer: B) B

33. Which of the following represents an infinite for loop?
A) for( ; ; )
B) for(;;)
C) Both A and B
D) for(1;1;1)
Answer: C) Both A and B

34. Which of these statements is valid for the switch control statement?
A) case values can be variables
B) case values must be floating type
C) case values must be constant expressions
D) case values can be strings in all versions
Answer: C) case values must be constant expressions

35. What will be the output?
int x = 1;
if(x == 1)
cout << “First”;
else if(x == 2)
cout << “Second”;
else
cout << “Other”;
A) Second
B) Other
C) First
D) None
Answer: C) First

36. The control variable in a for loop:
A) Can only be incremented
B) Can only be decremented
C) Can be modified in any way
D) Must be constant
Answer: C) Can be modified in any way

37. Which loop is guaranteed to execute at least once?
A) while
B) for
C) if
D) do-while
Answer: D) do-while

38. In an if-else chain, when multiple conditions are true:
A) Only the first true condition’s block executes
B) All true blocks execute
C) Last true condition executes
D) None executes
Answer: A) Only the first true condition’s block executes

39. What will be the output?
for(int i=1; i<=5; i++){
if(i%2==0) continue;
cout<<i<<” “;
}
A) 2 4
B) 1 3 5
C) 1 2 3 4 5
D) 5 3 1
Answer: B) 1 3 5

40. Which of the following correctly represents the syntax of a for loop?
A) for(condition; increment; initialization)
B) for(initialization; condition; increment)
C) for(increment; initialization; condition)
D) for(initialization; increment; condition)
Answer: B) for(initialization; condition; increment)

41. What is the output of the following code?
int i=0;
while(i<3)
{
cout<<i<<” “;
i+=2;
}
A) 0 1 2
B) 0 2
C) 1 3
D) Infinite loop
Answer: B) 0 2

42. What is the scope of a variable declared inside a for loop initialization in C++?
A) Global
B) Local to the loop
C) Function-level
D) Class-level
Answer: B) Local to the loop

43. The else part of an if-else structure executes when:
A) The condition is true
B) The condition is false
C) Always executes
D) Depends on compiler
Answer: B) The condition is false

44. What will be the output of the code below?
int i = 1;
while(i < 5)
{
if(i == 3) break;
cout << i << ” “;
i++;
}
A) 1 2 3 4
B) 1 2 3
C) 1 2
D) 1 2 4
Answer: C) 1 2

45. What happens if a break statement is used outside of any loop or switch?
A) Program ends
B) Compiler error
C) Executes as normal
D) Skips one statement
Answer: B) Compiler error

46. Which of the following statements is true for a for loop?
A) Initialization executes every iteration
B) Condition is tested before each iteration
C) Increment executes only once
D) All parts are mandatory
Answer: B) Condition is tested before each iteration

47. What is the output of the following code?
int i=0;
do{
i++;
if(i==2) continue;
cout<<i;
}while(i<3);
A) 123
B) 13
C) 12
D) 23
Answer: B) 13

48. Which of the following is NOT a decision-making statement in C++?
A) if
B) switch
C) goto
D) if-else
Answer: C) goto

49. In a nested loop, how many times does the inner loop execute in total?
A) Once
B) Depends on outer loop
C) (Outer loop iterations) × (Inner loop iterations)
D) Equal to outer loop
Answer: C) (Outer loop iterations) × (Inner loop iterations)

50. What is the output?
int x = 3;
if(x > 0)
if(x < 5)
cout << “Yes”;
else
cout << “No”;
A) No
B) Yes
C) Error
D) None
Answer: B) Yes

51. What will be the output?
int a=10;
if(a>5)
cout<<“A”;
else if(a>2)
cout<<“B”;
else
cout<<“C”;
A) B
B) C
C) A
D) None
Answer: C) A

52. A while loop in C++ executes:
A) A fixed number of times
B) As long as the condition remains true
C) At least once
D) Until false becomes true
Answer: B) As long as the condition remains true

53. What is the output?
int i=1;
for(; i<=3; )
{
cout<<i;
i++;
}
A) 12
B) 1234
C) 123
D) None
Answer: C) 123

54. Which of the following keywords cannot be used to terminate a loop in C++?
A) break
B) skip
C) return
D) exit
Answer: B) skip

55. Which loop is most suitable when the exact number of iterations is known beforehand?
A) while
B) for
C) do-while
D) if
Answer: B) for

56. The statement if(a=b) instead of if(a==b) will:
A) Assign b to a and check if a is non-zero
B) Compare a and b correctly
C) Generate syntax error
D) Return false always
Answer: A) Assign b to a and check if a is non-zero

57. Which of the following is not a valid relational operator in C++?
A) <
B) >=
C) ==
D) =>
Answer: D) =>

58. Which statement is used to transfer control to another part of the program unconditionally?
A) break
B) continue
C) return
D) goto
Answer: D) goto

59. What will be printed?
int i=0;
while(i<2)
{
int j=0;
while(j<2)
{
cout<<i<<j<<” “;
j++;
}
i++;
}
A) 00 01 10 11
B) 00 11
C) 01 10
D) 00 01 02
Answer: A) 00 01 10 11

60. What is the output?
int i=5;
do{
cout<<i<<” “;
i–;
}while(i>0);
A) 5 4 3 2
B) 5 4 3 2 1
C) 1 2 3 4 5
D) 5 4 3
Answer: B) 5 4 3 2 1

61. What will be the output of the following code?
int i=1;
while(i<=5)
{
if(i==4) break;
cout<<i<<” “;
i++;
}
A) 1 2 3
B) 1 2 3 4 5
C) 4 5
D) Infinite loop
Answer: A) 1 2 3

62. In C++, what happens if no case in a switch matches and there is no default?
A) The program crashes
B) Control simply skips the switch block
C) Garbage value is printed
D) The last case executes
Answer: B) Control simply skips the switch block

63. What is the output?
int x=0;
if(x)
cout<<“True”;
else
cout<<“False”;
A) True
B) Error
C) False
D) None
Answer: C) False

64. What is the main use of continue in loops?
A) To stop loop execution
B) To exit the program
C) To skip remaining code in current iteration
D) To repeat previous iteration
Answer: C) To skip remaining code in current iteration

65. Which control statement is not available in C++?
A) break
B) continue
C) goto
D) repeat-until
Answer: D) repeat-until

66. What will be the output?
int n=3;
do{
cout<<n<<” “;
n–;
}while(n>0);
A) 1 2 3
B) 3 2 1
C) 0 1 2
D) 3 2
Answer: B) 3 2 1

67. In nested loops, a break statement affects:
A) Only the loop in which it is written
B) All loops
C) Outer loop only
D) None
Answer: A) Only the loop in which it is written

68. Which of the following is an entry-controlled loop?
A) while
B) do-while
C) Both A and B
D) if-else
Answer: A) while

69. What happens if the condition of a while loop is false at the start?
A) Executes once
B) Executes twice
C) Does not execute at all
D) Infinite loop
Answer: C) Does not execute at all

70. What will be printed?
int x = 2;
switch(x+1){
case 1: cout<<“One”; break;
case 2: cout<<“Two”; break;
case 3: cout<<“Three”; break;
default: cout<<“None”;
}
A) Two
B) Three
C) None
D) One
Answer: B) Three

71. Which of these statements can alter the normal flow of a program?
A) if
B) break
C) for
D) while
Answer: B) break

72. The return statement:
A) Exits only loops
B) Exits from the current function
C) Exits from switch only
D) Pauses execution temporarily
Answer: B) Exits from the current function

73. Which of these control statements cannot be nested directly?
A) for
B) if
C) while
D) goto
Answer: D) goto

74. What is the output?
int a=5, b=10;
if(a>b)
cout<<“A”;
else
cout<<“B”;
A) A
B) B
C) AB
D) None
Answer: B) B

75. Which statement is used for conditional branching?
A) if-else
B) while
C) for
D) switch
Answer: A) if-else

76. In a for loop, if the condition is missing:
A) It results in an error
B) Loop runs once
C) It is treated as true (infinite loop)
D) It skips the loop
Answer: C) It is treated as true (infinite loop)

77. What is the output of this code?
int count=0;
for(int i=1;i<=3;i++){
for(int j=1;j<=2;j++)
count++;
}
cout<<count;
A) 3
B) 6
C) 9
D) 12
Answer: B) 6

78. Which loop executes at least once even if condition is false initially?
A) while
B) for
C) do-while
D) if
Answer: C) do-while

79. What will be printed?
for(int i=1;i<=5;i++){
if(i==3)
continue;
cout<<i<<” “;
}
A) 1 2 3 4 5
B) 1 2 4 5
C) 2 3 5
D) 1 3 4
Answer: B) 1 2 4 5

80. What does this code print?
int i=5;
while(i>0)
{
cout<<i<<” “;
i–;
}
A) 1 2 3 4 5
B) 5 4 3 2 1
C) 5 3 1
D) 1 3 5
Answer: B) 5 4 3 2 1

81. What will be the output?
int i = 0;
while(i < 3)
{
cout << i;
i++;
}
A) 1 2 3
B) 3 2 1
C) 0 1 2
D) 0 1 2 3
Answer: C) 0 1 2

82. The control will transfer to which part when a continue is encountered in a for loop?
A) Start of loop
B) End of loop
C) Update expression (increment/decrement part)
D) Condition check skipped
Answer: C) Update expression (increment/decrement part)

83. Which of these statements is true about a switch block?
A) It can test ranges of values
B) It compares an expression with constant case values
C) It can evaluate strings only
D) It allows float in case labels
Answer: B) It compares an expression with constant case values

84. What is the output?
int n=1;
do{
cout<<n<<” “;
n+=2;
}while(n<6);
A) 1 2 3 4 5
B) 1 3 5
C) 1 3
D) 1 5
Answer: B) 1 3 5

85. Which of the following cannot be used as a loop control variable in C++?
A) int
B) float
C) string
D) char
Answer: C) string

86. What will be the output of the following?
int a=1;
while(a<4){
cout<<a;
a+=2;
}
A) 1 2 3
B) 1 3
C) 1 2
D) 3 5
Answer: B) 1 3

87. Which statement about goto is correct?
A) It always jumps backward
B) It can only jump inside loops
C) It can jump to any labeled statement within the same function
D) It is faster than loops
Answer: C) It can jump to any labeled statement within the same function

88. What happens when the condition in a for loop is omitted?
A) Loop executes once
B) It creates an infinite loop
C) Compiler error
D) Skips initialization
Answer: B) It creates an infinite loop

89. What is the output?
int i=1;
for(; i<=3; i++)
{
if(i==2) continue;
cout<<i<<” “;
}
A) 1 2 3
B) 1 3
C) 2 3
D) 3
Answer: B) 1 3

90. The if-else structure can be replaced with which of the following in simple assignments?
A) loop
B) Ternary operator (?:)
C) goto
D) switch
Answer: B) Ternary operator (?:)

91. Which of these is not a looping construct in C++?
A) for
B) while
C) do-while
D) repeat-until
Answer: D) repeat-until

92. What is the output?
int x = 0;
if(x == 0)
cout<<“Zero”;
else
cout<<“Non-zero”;
A) Non-zero
B) Zero
C) Null
D) No output
Answer: B) Zero

93. What is the advantage of a switch statement over multiple if-else?
A) Better readability and efficiency
B) It can test any data type
C) No need for break statements
D) Allows floating values
Answer: A) Better readability and efficiency

94. What will this code print?
for(int i=3; i>0; i–)
{
cout<<i<<” “;
}
A) 1 2 3
B) 3 2 1
C) 1 3 2
D) 3 1
Answer: B) 3 2 1

95. What happens if there is a return inside the main function before the end?
A) It skips next line
B) Program terminates immediately
C) Jumps to start
D) Waits for user input
Answer: B) Program terminates immediately

96. Which of the following is not allowed in a switch case?
A) int
B) char
C) enum
D) float
Answer: D) float

97. In nested loops, how many times will the inner loop execute if outer runs 3 times and inner runs 4 times?
A) 4
B) 3
C) 12
D) 7
Answer: C) 12

98. What is the output of this code?
int i=2;
if(i>5)
cout<<“High”;
else if(i>1)
cout<<“Mid”;
else
cout<<“Low”;
A) High
B) Low
C) Mid
D) None
Answer: C) Mid

99. Which of the following can be used to terminate both loop and function?
A) continue
B) return
C) break
D) exit(1)
Answer: B) return

100. What is the output?
int i=1;
do{
if(i==4) break;
cout<<i<<” “;
i++;
}while(i<=5);
A) 1 2 3 4 5
B) 1 2 3 4
C) 1 2 3
D) 1 3 5
Answer: C) 1 2 3