WorksheetsDCS1101 - Week 14 (Revision Quiz)
Total questions: 50
Worksheet time: 43mins
What is the output of this code?
int a = 5;
int b = a++;
cout << b;
Which type is most appropriate for storing extremely large whole numbers?
int
short
long
float
What is the size of a double on most 64-bit systems?
What happens if you use an uninitialized variable?
Which keyword prevents a variable from being modified?
Which of the following is a valid C++ variable name?
2value
value_2
double
value-2
What is the output?
int x = 7;
if (x > 10)
cout << "A";
else if (x > 5)
cout << "B";
else
cout << "C";
Which math operator is evaluated first?
What is the output?
int a = 5, b = 10;
cout << (a > 3 && b < 5);
Which statement exits a loop immediately?
continue
skip
break
stop
What is the result of:
if (true || false && false)
What is the output?
for (int i = 1; i < 5; i += 2)
cout << i;
For which scenario is a do-while loop best used?
When loop may run zero times
When loop must run at least once
For fixed number of iterations
For infinite loops only
What is wrong with this loop?
int i = 0;
while (i < 10)
cout << i;
What does this code print?
int sum = 0;
for (int i = 1; i <= 5; i++)
sum += i;
cout << sum;
Which breaks only the current iteration, not the loop?
exit
break
continue
skip
What is the output?
int x = 0;
do {
x++;
} while (x < 3);
cout << x;
Which is required before calling a function defined below main()?
Function declaration or prototype
What does “passing by value” mean in functions?
Passing a reference to the variable instead of its value.
A copy of the variable's value is passed, not the variable itself.
The function can modify the original variable.
The variable itself is passed directly.
What is the output?
int f(int x) {
return x * 2;
}
cout << f(3 + 2);
What does a function without a return type default to?
What keyword prevents a function from modifying an argument?
What is function overloading?
The process of merging multiple functions into one.
Multiple functions with the same name to coexist, differentiated by their parameter types or counts.
A method to increase the speed of functions.
Functions to be executed in parallel without parameters.
Valid array declaration?
int arr(5);
int arr[5];
array arr[5];
declare arr[5];
What is the index of the last element in int a[20];?
What is the output?
int a[5] = {10, 20, 30, 40, 50};
cout << a[2];
Arrays are always passed to functions as…
What is wrong with this?
int arr[3];
arr[3] = 10;
What does this code do?
int arr[3] = {1,2,3};
cout << arr;
What is the output?
int a[5] = {5};
cout << a[1];
Correct syntax to declare a structure?
struct x { int a; } ;
structure x { int a; };
class struct x { int a; };
define struct x { int a; };
What symbol is used to access structure members with?
What is the output?
struct S { int a; };
S s = {10};
cout << s.a;
What does this code do?
struct A { int x; };
A a1 = {5};
A a2 = a1;
What is selection sort’s strategy?
Repeatedly divide the array in half.
Merge sorted portions into one.
Select the minimum element from the unsorted portion and move it to the sorted portion.
Swap adjacent elements until sorted.
What indicates bubble sort is finished early?
Output after 1st pass of bubble sort?
Array: { 5, 1, 4, 2 }
Requirement for binary search?
Binary search midpoint formula:
What is the best technique to break a large problem into small parts?
Which is the best algorithm to track minimum values in an array?
Linear search
What is a sentinel value used for?
What is the most efficient tool to validate input?
Loops + conditions
Switch-only
Arrays
Structures
Explain the difference between global and local variables in C++.
Describe a situation where a while loop is more appropriate than a for loop.
Why is binary search faster than linear search?
What problem-solving steps would you apply when designing a program to calculate student CGPA?
Draw a flowchart to check whether a number is even or odd.

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

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

