Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Multiple Choice Questions
Q111: What is the output of the following for loop? for (int i = 0; i < 5; i++) { cout << i; }
- A: 1234
- B: 12345
- C: 12345
- D: 1234
View Answer
A
Q112: In the for loop for (int i = 0; i < 10; i++), what happens when i becomes 10?
- A: The loop continues indefinitely
- B: The loop terminates
- C: The loop resets i to 0
- D: An error occurs
View Answer
B
Q113: What is the purpose of the continue statement in a loop?
- A: To exit the loop immediately
- B: To skip the rest of the loop body for the current iteration
- C: To reset the loop variable
- D: To repeat the loop from the beginning
View Answer
B
Q114: In the code x = ++j;, what happens to the value of j after execution?
- A: j is incremented first and then assigned to x
- B: j is used first in the expression, then incremented
- C: j remains the same
- D: An error occurs
View Answer
A
Q115: What does the -- operator do in the expression counter--?
- A: Decreases the value of counter by 1
- B: Increases the value of counter by 1
- C: Decreases the value of counter by 2
- D: Increases the value of counter by 2
View Answer
A
Q116: Which of the following statements is true for the for loop syntax?
- A: The initialization, condition, and increment parts are optional
- B: The condition part is optional
- C: The initialization part is optional
- D: The increment part is optional
View Answer
A
Q117: What will the following code output? for (int i = 5; i < 5; i++) { cout << i; }
- A: No output
- B: 5
- C: 1234
- D: 12345
View Answer
A
Q118: What will the result be of x += 10; if x is initially 5?
- A: x will be 10
- B: x will be 15
- C: x will be 5
- D: x will be 50
View Answer
B
Q119: What is the primary advantage of using a switch statement over multiple if statements?
- A: More readable and easier to manage
- B: Faster execution speed
- C: Requires fewer lines of code
- D: Can handle complex conditions
View Answer
A
Q120: What will happen if you forget to include a break statement in a switch case?
- A: The program will terminate
- B: The next case will be executed
- C: The program will run slower
- D: The switch statement will be ignored
View Answer
B