WorksheetsLevel 3 Questions
Total questions: 30
Worksheet time: 15mins
Which of the following is a correct variable declaration in C++?
int 3value;
int value_3;
float& value;
string name = 123;
What is the output of 10 % 3?
3
1
0
10
Which operator is used for assignment in C++?
==
=
:=
=>
What does the && operator do?
Adds two numbers
Checks OR condition
Logical AND
Ends the loop
Which data type is used to store a single character?
string
char
int
float
What is the output of if(5 > 3) cout << "Yes"; else cout << "No";
No
Error
Yes
Nothing
Which of these is a comparison operator?
+
=
!=
&&
What will this loop do? int i = 0; while(i < 5) { i++; }
Run 4 times
Run forever
Run 5 times
Error
What will the following print? int x = 5; if(x % 2 == 0) cout << "Even"; else cout << "Odd";
Even
Odd
5
Error
Which loop runs at least once, even if the condition is false?
for
while
do-while
None
Which symbol is used to access array elements?
()
{}
[]
<>
How do you declare a 2D array of integers with 5 rows and 3 columns?
int arr(5)(3);
int arr[3][5];
int arr[5][3];
int arr{5,3};
What does continue do in a loop?
Stops the loop completely
Skips the rest of current iteration
Repeats the last step
Ends the program
What does break do in a loop?
Ends all loops
Exits only the current iteration
Exits the loop completely
Starts loop again
Which keyword is used to define a function in C++?
def
void
function
declare
What is the index of the first element in an array?
1
0
-1
Depends on size
What is the correct way to call this function? int sum(int a, int b);
sum a b;
sum(a + b);
sum(3, 4);
call sum 3, 4;
Which loop is best when the number of iterations is known?
while
do-while
for
switch
What will x += 2 do?
x = x + 2
x = 2
Error
x = 2 + x + 2
What happens if you forget break in a switch case?
It gives an error
It exits the switch
It executes the next case(s)
Skips all
What does return do inside a function?
Repeats function
Exits function and sends a value back
Pauses function
Skips all code
If int arr[3] = {5, 10, 15};, what is arr[1]?
5
10
15
1
Which of the following is a valid function definition?
int sum(a, b)
sum(int a, int b)
int sum(int a, int b)
def sum(a, b)
Which symbol is used to end a statement in C++?
:
;
.
,
In a for loop: for(int i = 0; i < 5; i++), how many times does the loop run?
6
4
5
0
The while loop always runs at least once.
True
False
Arrays in C++ start from index 0.
True
False
continue exits the entire loop.
False
True
The modulus operator % gives the remainder.
True
False
Functions can be called before they are defined.
False
True
