Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

DCS1101 - Week 14 (Revision Quiz)

Total questions: 50

Worksheet time: 43mins

Name
Class
Date
1.

What is the output of this code?

int a = 5;

int b = a++;

cout << b;

a)
5.0
b)
5
c)
4
d)
6
2.

Which type is most appropriate for storing extremely large whole numbers?

a)

int

b)

short

c)

long

d)

float

3.

What is the size of a double on most 64-bit systems?

a)
8 bytes
b)
12 bytes
c)
16 bytes
d)
4 bytes
4.

What happens if you use an uninitialized variable?

a)
An uninitialized variable can only be used in loops.
b)
An uninitialized variable will always return zero.
c)
Using an uninitialized variable guarantees a successful operation.
d)
An uninitialized variable may cause errors or use default values.
5.

Which keyword prevents a variable from being modified?

a)
let
b)
const
c)
var
d)
mutable
6.

Which of the following is a valid C++ variable name?

a)

2value

b)

value_2

c)

double

d)

value-2

7.

What is the output?

int x = 7;

if (x > 10)

cout << "A";

else if (x > 5)

cout << "B";

else

cout << "C";

a)
A
b)
C
c)
D
d)
B
8.

Which math operator is evaluated first?

a)
All operators are evaluated simultaneously.
b)
Operators with lower precedence are evaluated first.
c)
Operators with higher precedence are evaluated first.
d)
Operators are evaluated based on their position in the expression.
9.

What is the output?

int a = 5, b = 10;

cout << (a > 3 && b < 5);

a)
0
b)
10
c)
5
d)
1
10.

Which statement exits a loop immediately?

a)

continue

b)

skip

c)

break

d)

stop

11.

What is the result of:

if (true || false && false)

a)
false
b)
true && false
c)
false || true
d)
true
12.

What is the output?

for (int i = 1; i < 5; i += 2)

cout << i;

a)
24
b)
12
c)
34
d)
13
13.

For which scenario is a do-while loop best used?

a)

When loop may run zero times

b)

When loop must run at least once

c)

For fixed number of iterations

d)

For infinite loops only

14.

What is wrong with this loop?

int i = 0;

while (i < 10)

cout << i;

a)
The loop will cause an infinite loop because 'i' is never incremented.
b)
The loop will only print even numbers from 0 to 10.
c)
The loop will print 'i' in reverse order.
d)
The loop will terminate after printing 'i' once.
15.

What does this code print?

int sum = 0;

for (int i = 1; i <= 5; i++)

sum += i;

cout << sum;

a)
20
b)
5
c)
15
d)
10
16.

Which breaks only the current iteration, not the loop?

a)

exit

b)

break

c)

continue

d)

skip

17.

What is the output?

int x = 0;

do {

x++;

} while (x < 3);

cout << x;

a)
2
b)
4
c)
3
d)
0
18.

Which is required before calling a function defined below main()?

a)

Function declaration or prototype

b)
Function call without parameters
c)
Variable initialization before function
d)
Return statement inside main()
19.

What does “passing by value” mean in functions?

a)

Passing a reference to the variable instead of its value.

b)

A copy of the variable's value is passed, not the variable itself.

c)

The function can modify the original variable.

d)

The variable itself is passed directly.

20.

What is the output?

int f(int x) {

return x * 2;

}

cout << f(3 + 2);

a)
6
b)
10
c)
12
d)
8
21.

What does a function without a return type default to?

a)
void
b)
float
c)
string
d)
int
22.

What keyword prevents a function from modifying an argument?

a)
const
b)
mutable
c)
variable
d)
modifiable
23.

What is function overloading?

a)

The process of merging multiple functions into one.

b)

Multiple functions with the same name to coexist, differentiated by their parameter types or counts.

c)

A method to increase the speed of functions.

d)

Functions to be executed in parallel without parameters.

24.

Valid array declaration?

a)

int arr(5);

b)

int arr[5];

c)

array arr[5];

d)

declare arr[5];

25.

What is the index of the last element in int a[20];?

a)
18
b)
19
c)
17
d)
20
26.

What is the output?

int a[5] = {10, 20, 30, 40, 50};

cout << a[2];

a)
30
b)
50
c)
40
d)
20
27.

Arrays are always passed to functions as…

a)
Values
b)
Pointers
c)
References
d)
Copies
28.

What is wrong with this?

int arr[3];

arr[3] = 10;

a)
You can access arr[3] without any issues.
b)
You cannot access arr[3] because it is out of bounds.
c)
The array size should be declared as 4.
d)
You can assign values to arr[3] safely.
29.

What does this code do?

int arr[3] = {1,2,3};

cout << arr;

a)
Outputs the size of the array.
b)
Outputs the memory address of the first element of the array.
c)
Displays the last element of the array.
d)
Prints the elements of the array.
30.

What is the output?

int a[5] = {5};

cout << a[1];

a)
-1
b)
1
c)
0
d)
5
31.

Correct syntax to declare a structure?

a)

struct x { int a; } ;

b)

structure x { int a; };

c)

class struct x { int a; };

d)

define struct x { int a; };

32.

What symbol is used to access structure members with?

a)
::
b)
->
c)
[]
d)
.
33.

What is the output?

struct S { int a; };

S s = {10};

cout << s.a;

a)
10
b)
5
c)
10.0
d)
20
34.

What does this code do?

struct A { int x; };

A a1 = {5};

A a2 = a1;

a)
The code initializes two instances of a struct with the same value.
b)
The code assigns a new value to an existing instance of a struct.
c)
The code defines a struct but does not create any instances.
d)
The code creates a single instance of a struct with a default value.
35.

What is selection sort’s strategy?

a)

Repeatedly divide the array in half.

b)

Merge sorted portions into one.

c)

Select the minimum element from the unsorted portion and move it to the sorted portion.

d)

Swap adjacent elements until sorted.

36.

What indicates bubble sort is finished early?

a)
The last element is the smallest value.
b)
No swaps during a complete pass.
c)
The first element is the largest value.
d)
All elements are sorted in ascending order.
37.

Output after 1st pass of bubble sort?

Array: { 5, 1, 4, 2 }

a)
{1, 4, 2, 5}
b)
{5, 1, 2, 4}
c)
{4, 1, 2, 5}
d)
{1, 5, 2, 4}
38.

Requirement for binary search?

a)
A sorted array or list.
b)
An unsorted array or list.
c)
A linked list structure.
d)
A binary tree data structure.
39.

Binary search midpoint formula:

a)
mid = left + (right - left) / 2
b)
mid = (left - right) / 2
c)
mid = left + right / 2
d)
mid = (left + right) / 2
40.

What is the best technique to break a large problem into small parts?

a)
Divide and conquer
b)
Fragment and address
c)
Break and solve
d)
Split and analyze
41.

Which is the best algorithm to track minimum values in an array?

a)
Depth-first search algorithm
b)
Bubble sort algorithm
c)

Linear search

d)
Binary search algorithm
42.

What is a sentinel value used for?

a)
To mark boundaries or special conditions in data structures or algorithms.
b)
To represent user input in a user interface.
c)
To enhance the performance of sorting algorithms.
d)
To store temporary data during program execution.
43.

What is the most efficient tool to validate input?

a)

Loops + conditions

b)

Switch-only

c)

Arrays

d)

Structures

44.

Explain the difference between global and local variables in C++.

4 lines
45.

Describe a situation where a while loop is more appropriate than a for loop.

4 lines
46.

Why is binary search faster than linear search?

4 lines
47.

What problem-solving steps would you apply when designing a program to calculate student CGPA?

4 lines
48.

Draw a flowchart to check whether a number is even or odd.

49.

Draw a memory layout showing how an array of 5 integers is stored.

50.

Draw a flowchart showing the steps of a for loop from 1 to 5.