You are on page 1of 6

CSDC101 Prefinal Exam Practice Set

1. What is the purpose of the if statement in C++?


a) To declare variables
b) To create loops
c) To perform conditional execution
d) To define a sequence
2. How is a switch statement different from an if statement?
a) switch is used for repetition, if for selection
b) if can handle multiple conditions, switch is for single values
c) switch is used for declaring variables, if for assigning values
d) There is no difference
3. What is the purpose of the break statement in a switch statement?
a) To terminate the program
b) To end the current loop iteration
c) To exit the switch statement
d) To skip the next iteration of a loop
4. In C++, what is the purpose of the while loop?
a) To create an infinite loop
b) To repeat a block of code while a condition is true
c) To iterate through a range of values
d) To ensure a block of code is executed at least once
9. What is the primary purpose of the do-while loop?
a) To create an infinite loop
b) To repeat a block of code while a condition is true
c) To ensure a block of code is executed at least once
d) To iterate through a range of values
10. What is the key difference between for and while loops in C++?
a) for is used for selection, while for repetition
b) for can handle multiple conditions, while is for single conditions
c) for initializes a counter and increments it, while does not
d) There is no difference
11. What does the continue statement do in a loop?
a) Exits the loop
b) Skips the current iteration and continues with the next one
c) Ends the program
d) Breaks out of the loop
12. What is the purpose of the break statement in a loop?
a) To end the program
b) To exit the current loop
c) To skip the next iteration of a loop
d) To terminate the loop and proceed to the next loop
17. How does a nested loop differ from a regular loop in C++?
a) Nested loops cannot be used in C++
b) Nested loops have only one level of iteration
c) Nested loops contain another loop within their block
d) There is no difference

a) Outputs a multiplication table up to 3x2


b) Prints the sum of 'i' and 'j'
c) Creates an infinite loop
d) Does nothing

You might also like