WorksheetsLevel_Two_Exam
Total questions: 37
Worksheet time: 37mins
What is a variable in C++?
A kind of loop
A container that stores data
A condition
A function name
Which of the following is a correct way to declare an integer variable in C++?
int number;
number int;
int = number;
number = int;
What does an "if" statement do in C++?
Repeats a block of code
Runs code only if a condition is true
Declares a variable
Stops the program
Which line shows a correct if condition in C++?
if x == 5
if (x == 5)
if x = 5
if x : 5
Which loop is used when you know how many times you want to repeat something?
if loop
do loop
for loop
switch loop
Which part of the for loop controls how many times the loop repeats?
The condition in the middle
The first part only
The last part only
None of the parts
What is the difference between a while loop and a do-while loop?
while runs at least once; do-while may not
do-while runs at least once; while may not
They are exactly the same
do-while cannot have conditions
Which loop checks the condition after the loop body?
for loop
while loop
do-while loop
if statement
What is an array in C++?
A single number
A loop
A group of variables of the same type
A condition
How do you access the first element of an array called marks?
marks(0)
marks.0
marks[0]
marks{0}
Which of these is a correct variable name in C++?
2value
my value
my_value
int
What will happen if you use a variable without declaring it?
The program runs faster
The program gives an error
It prints 0
It ignores the variable
What is the output of this code? int x = 10; cout << x;
0
x
10
Nothing
What type of variable stores decimal numbers in C++?
int
string
float
bool
Which symbol means "equal to" in an if condition?
=
==
!=
<=
Which symbol means "not equal to"?
=
<>
!=
!==
What does this condition check? if (score > 50)
If score is 50
If score is less than 50
If score is more than 50
If score is equal to 50
What does the following code do? for (int i = 0; i < 5; i++) cout << i << " ";
Prints 1 2 3 4 5
Prints 0 1 2 3 4
Prints 0 1 2 3 4 5
Prints nothing
How many times does this loop run? for (int i = 0; i < 3; i++)
2
4
3
1
What part of a for loop updates the counter?
The first part
The second part
The third part
The body
When does a while loop stop repeating?
When the user says stop
When the condition becomes false
After 10 times
It never stops
What is the output of this code? int i = 0; while (i < 3) { cout << i; i++; }
0 1 2
1 2 3
0 1 2 3
Infinite loop
When is the condition checked in a do-while loop?
Before the loop starts
After the loop ends
After each loop run
Never
What is the index of the first element in a C++ array?
0
1
-1
10
What will this print? int arr[3] = {10, 20, 30}; cout << arr[1];
10
20
30
Error
How many elements are in this array? int nums[5];
0
4
5
6
Which of these correctly accesses the last element in int a[4] = {1, 2, 3, 4};
a[4]
a[3]
a[1]
a[0]
You can use a variable in C++ without declaring it first. (True/False)
True
False
The 'if' statement is used to make decisions in a program. (True/False)
True
False
In C++, the 'for' loop can be used to repeat code multiple times. (True/False)
True
False
This line is correct: int 5number = 10; (True/False)
True
False
An array can store more than one value of the same type. (True/False)
True
False
In a 'while' loop, the condition is checked after the code runs. (True/False)
True
False
The 'do-while' loop always runs the code at least once. (True/False)
True
False
You can print values in C++ using cout. (True/False)
True
False
The first element in an array is always at index 1. (True/False)
True
False
This is a valid if condition: if (x = 5) (True/False)
True
False
