Introduction to Programming MCQs with Answers
Practice important Introduction to Programming MCQs with answers and explanations.
Chapter: 6
Q101:
What will happen if the value of the variable used in the 'while' condition does not change?
A. The loop becomes an infinite loop
B. The loop will execute only once
C. The loop will execute zero times
D. The loop will produce an error
Correct Answer:
A
Chapter: 6
Q102:
What is the output of the sample program if the user inputs 10 as the upper limit?
A. The sum of even numbers is 30
B. The sum of even numbers is 25
C. The sum of even numbers is 20
D. The sum of even numbers is 15
Correct Answer:
A
Chapter: 6
Q103:
Which of the following is NOT true about the 'while' loop?
A. 'while' loop can only execute more than once
B. 'while' loop must have a fixed number of repetitions
C. 'while' loop may execute zero times
D. 'while' loop executes exactly once
Correct Answer:
C
Chapter: 6
Q104:
How can you calculate the factorial of a given number in C?
A. By using a 'while' loop that multiplies decremented values of the number
B. By using a 'for' loop that multiplies decremented values of the number
C. By using a 'do-while' loop
D. By using a recursive function
Correct Answer:
A
Chapter: 6
Q105:
What is the significance of indentation in a 'while' loop?
A. To make the code easy to understand
B. To increase the execution speed
C. To reduce the number of statements
D. To make the code execute faster
Correct Answer:
A
Chapter: 6
Q106:
What is the result of the statement 'number = number + 1' in a loop?
A. It generates the next integer
B. It resets the loop
C. It decreases the number by 1
D. It multiplies the number by 1
Correct Answer:
C
Chapter: 6
Q107:
In a flowchart, which symbol represents a decision or condition?
A. Rectangle
B. Diamond
C. Circle
D. Triangle
Correct Answer:
B
Chapter: 6
Q108:
What should be done first, according to the text: coding the program or drawing the flowchart?
A. Coding the program
B. Drawing the flowchart
C. Both can be done simultaneously
D. Neither is necessary
Correct Answer:
B
Chapter: 7
Q109:
In a do-while loop, when is the condition evaluated?
A. Before the loop body executes
B. After the loop body executes
C. During each iteration of the loop
D. It is not evaluated
Correct Answer:
B
Chapter: 7
Q110:
What will the following do-while loop print if c is 'z' and tryNum is initially 0?
A. "Congratulations, Your guess is correct"
B. No output
C. The character 'z'
D. "Please enter a character between a-z"
Correct Answer:
A
Chapter: 7
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
Correct Answer:
A
Chapter: 7
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
Correct Answer:
B
Chapter: 7
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
Correct Answer:
B
Chapter: 7
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
Correct Answer:
A
Chapter: 7
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
Correct Answer:
A
Chapter: 7
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
Correct Answer:
A
Chapter: 7
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
Correct Answer:
A
Chapter: 7
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
Correct Answer:
B
Chapter: 8
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
Correct Answer:
A
Chapter: 8
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
Correct Answer:
B