Unit 1: Foundational Concepts - Practice Quiz

INT322 — Computing System And Technologies 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which feature is supported by C++ but not directly by C?

Introduction to C/C++ Easy
A. Classes and objects
B. Arithmetic operators
C. Built-in integers
D. Conditional statements

2 Which data type is commonly used to store a single character in C and C++?

Data types Easy
A. int
B. char
C. float
D. double

3 What is a variable in a program?

Variables Easy
A. A type of loop
B. A fixed program instruction
C. A named storage location
D. A compiler message

4 Which C++ keyword can be used to declare a constant?

Constants Easy
A. const
B. static
C. return
D. void

5 Which object is commonly used to display output in C++?

Reading and writing data using scanf, printf, cin and cout Easy
A. scanf
B. cout
C. cin
D. sizeof

6 Which control structure repeatedly executes code while a condition remains true?

Control structures: if-else and loops Easy
A. while loop
B. switch label
C. if statement
D. else clause

7 What does a function declaration tell the compiler?

Functions: declaration and definition Easy
A. The function's execution result
B. The function's name and signature
C. The program's memory usage
D. The loop's repetition count

8 What is passed to a function during call by value?

Call by value and call by reference Easy
A. The argument's memory address
B. The variable's data type
C. A copy of the argument
D. The function's return type

9 What is recursion?

Recursion Easy
A. A loop declaring a variable
B. A function calling itself
C. A compiler checking syntax
D. A class creating an object

10 Which concept combines data and related functions within one unit?

Introduction to object-oriented programming Easy
A. Encapsulation
B. Iteration
C. Compilation
D. Recursion

11 Which keyword defines a structure in C++?

User-defined data types: struct and class Easy
A. template
B. namespace
C. typedef
D. struct

12 What is an object in C++?

Classes and objects Easy
A. A declaration of a loop
B. A category of operator
C. An instance of a class
D. A standard input function

13 When is a constructor normally called in C++?

Manager functions: constructors and destructors Easy
A. When an object is created
B. When a function returns
C. When a loop is repeated
D. When input is received

14 What is the main purpose of a data structure?

Introduction to data structures Easy
A. To translate source code
B. To display compiler errors
C. To control hardware voltage
D. To organize and store data

15 Which of the following is a linear data structure?

Types of data structures Easy
A. Tree
B. Graph
C. Array
D. Heap

16 What does time complexity describe?

Time and space complexity analysis Easy
A. Number of variable names
B. Number of output devices
C. Growth in running time
D. Growth in source-code length

17 What does a time-space trade-off mean?

Time-space trade-off Easy
A. Using more input to reduce output
B. Using more classes to remove data
C. Using more memory to save time
D. Using more syntax to save code

18 What does Big-O notation commonly express?

Big-O notation Easy
A. An asymptotic upper bound
B. An exact memory address
C. An exact machine runtime
D. An asymptotic lower bound

19 What does Big-Omega notation commonly express?

Big-Omega notation Easy
A. An exact loop count
B. An asymptotic lower bound
C. An exact input size
D. An asymptotic upper bound

20 What does indicate about an algorithm's growth?

Big-Theta notation Easy
A. It remains constant
B. It grows quadratically
C. It grows linearly
D. It grows logarithmically

21 A C++ program defines int process(int) and double process(double). Which feature allows process(4) and process(4.5) to select different functions?

Introduction to C/C++ Medium
A. Macro substitution
B. Function overloading
C. Function overriding
D. Operator precedence

22 What does cout << fixed << setprecision(1) << 7 / 2; display when the required headers are included?

Data types Medium
A. 3.5
B. 4.0
C. 3.0
D. 3.2

23 What is printed by int x = 5; { int x = 8; cout << x << " "; } cout << x;?

Variables Medium
A. 8 5
B. 5 8
C. 8 8
D. 5 5

24 Given int a = 1, b = 2; const int* p = &a;, which statement is valid?

Constants Medium
A. (*p)++;
B. *p = 3;
C. p = &b;
D. *p = b;

25 Which pair correctly reads an int n and a double x using C input and then using C++ input?

Reading and writing data using scanf, printf, cin and cout Medium
A. scanf("%d %lf", &n, &x); and cin >> n >> x;
B. scanf("%d %lf", n, x); and cin >> x >> n;
C. scanf("%d %f", &n, &x); and cin << n << x;
D. scanf("%f %lf", &n, &x); and cout >> n >> x;

26 What is the final value of sum? int sum = 0; for (int i = 1; i <= 6; i++) { if (i % 2 == 0) continue; sum += i; if (sum > 5) break; }

Control structures: if-else and loops Medium
A. 9
B. 16
C. 21
D. 4

27 Given the declaration int combine(int, int = 2); and definition int combine(int a, int b) { return a + b; }, what does combine(5) return?

Functions: declaration and definition Medium
A. 5
B. 2
C. 7
D. A compilation error

28 What is printed by void update(int a, int& b) { a += 2; b += 2; } int x = 3, y = 3; update(x, y); cout << x << " " << y;?

Call by value and call by reference Medium
A. 5 5
B. 3 3
C. 3 5
D. 5 3

29 How many total function invocations occur for f(4), including the initial call, if f(n) returns immediately when and otherwise calls f(n-1) and f(n-2)?

Recursion Medium
A. 7
B. 12
C. 8
D. 9

30 If Base declares virtual void show() and Derived overrides it, which implementation runs for Base* p = new Derived; p->show();?

Introduction to object-oriented programming Medium
A. Both implementations
B. Derived::show()
C. Neither implementation
D. Base::show()

31 Consider struct S { int x; }; and class C { int x; };. Without adding access specifiers, which statement is correct?

User-defined data types: struct and class Medium
A. Both data members are public
B. S::x is private and C::x is public
C. S::x is public and C::x is private
D. Both data members are private

32 A Counter class has a non-static member value initialized to 0, an increment() method, and a get() method. If object a is incremented twice and object b once, what do a.get() and b.get() return?

Classes and objects Medium
A. 1 and 2
B. 2 and 1
C. 2 and 2
D. 3 and 3

33 A Derived object contains a member object Member and inherits from Base. Which order is used for construction and destruction?

Manager functions: constructors and destructors Medium
A. Construct Base, Derived, Member; destroy Member, Derived, Base
B. Construct Base, Member, Derived; destroy Derived, Member, Base
C. Construct Member, Base, Derived; destroy Derived, Base, Member
D. Construct Derived, Base, Member; destroy Member, Base, Derived

34 A browser must implement a Back operation that returns to the most recently visited page first. Which data structure best matches this requirement?

Introduction to data structures Medium
A. Hash table
B. Stack
C. Queue
D. Binary heap

35 For a sparse graph with vertices and relatively few edges , which representation usually uses space?

Types of data structures Medium
A. Adjacency matrix
B. Two-dimensional array
C. Vertex incidence cube
D. Adjacency list

36 What are the time and auxiliary-space complexities of for (int i = 0; i < n; i++) for (int j = 1; j < n; j *= 2) count++;?

Time and space complexity analysis Medium
A. time and space
B. time and space
C. time and space
D. time and space

37 A program repeatedly computes an expensive deterministic result for the same inputs. Which change most directly trades additional space for reduced execution time?

Time-space trade-off Medium
A. Replace iteration with recursion
B. Recalculate results on demand
C. Compress every input before use
D. Cache previously computed results

38 What is the tightest Big-O bound among the choices for ?

Big-O notation Medium
A.
B.
C.
D.

39 A loop performs one constant-time operation for every integer from 1 through n. What is its tightest listed asymptotic lower bound?

Big-Omega notation Medium
A.
B.
C.
D.

40 What is the Big-Theta complexity of for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) count++;?

Big-Theta notation Medium
A.
B.
C.
D.

41 Assume the following source is compiled once as C and once as C++:

#include <stdlib.h>

int main(void) { int *p = malloc(sizeof *p); free(p); }

Which statement is correct?

Introduction to C/C++ Hard
A. It is valid C but ill-formed C++ because C++ does not implicitly convert void * to int *.
B. It is valid C++ but ill-formed C because C requires an explicit cast of the result from malloc.
C. It is valid in both languages because malloc automatically returns the requested pointer type.
D. It is ill-formed in both languages because sizeof *p dereferences an uninitialized pointer.

42 What does the following C++ expression print?

int i = -1; unsigned int u = 1; std::cout << (i < u);

Data types Hard
A. The result is undefined because negative integers cannot be converted to unsigned.
B. 1, because the signed value -1 is numerically smaller than unsigned 1.
C. 0, because i is converted to a large unsigned value before comparison.
D. 0, because every comparison between signed and unsigned values is false.

43 Given the following C++ program fragment, what is printed?

int x = 1;

void f() {
static int x = 2;
{ int x = 7; ++x; }
std::cout << ++x << ' ';
}

int main() { f(); f(); std::cout << x; }

Variables Hard
A. 3 4 4
B. 3 4 1
C. 3 3 1
D. 8 8 1

44 For the declarations below, which statement is well-formed C++?

int a = 1, b = 2;
const int *p = &a;
int * const q = &a;

Constants Hard
A. q = &b;
B. constexpr int r = a + 1;
C. p = &b;
D. *p = 3;

45 The input consists of 42 followed immediately by a newline. What values result from this C statement?

int n = 0; char c = 'X'; int r = scanf("%d%c", &n, &c);

Reading and writing data using scanf, printf, cin and cout Hard
A. r is 1, n is 4, and c contains the character 2.
B. r is 2, n is 42, and c contains the newline.
C. r is 2, n is 42, and c contains the next non-whitespace character.
D. r is 1, n is 42, and c remains equal to X.

46 Let , where , and assume arithmetic does not overflow. How many times is work() called?

for (int i = 1; i <= n; i *= 2)
for (int j = i; j >= 1; j /= 2)
work();

Control structures: if-else and loops Hard
A.
B.
C.
D.

47 Which pair of C++ declarations introduces two distinct overloads rather than conflicting declarations or repeated declarations of the same function?

Functions: declaration and definition Hard
A. int f(int); and double f(int);
B. void f(int); and void f(const int);
C. void f(int *); and void f(const int *);
D. void f(int *); and void f(int * const);

48 What is printed by this C++ code?

void transform(int &a, int &b) { a += 2; b *= 3; }

int x = 4;
transform(x, x);
std::cout << x;

Call by value and call by reference Hard
A. 18
B. 6
C. 12
D. The call is ill-formed.

49 For powers of two, what is the time complexity of this function if each addition, comparison, and division costs constant time?

int solve(int n) {
if (n <= 1) return 1;
return solve(n / 2) + solve(n / 2) + n;
}

Recursion Hard
A.
B.
C.
D.

50 What is printed when a Derived object is constructed?

struct Base {
Base() { identify(); }
virtual void identify() { std::cout << "Base"; }
};

struct Derived : Base {
void identify() override { std::cout << "Derived"; }
};

Derived object;

Introduction to object-oriented programming Hard
A. BaseDerived
B. The behavior is undefined.
C. Derived
D. Base

51 Consider these C++ definitions:

struct S { int x; };
class C { int x; };
struct D : S {};
class E : S {};

From an unrelated function, for which objects is direct access through object.x permitted?

User-defined data types: struct and class Hard
A. S and D objects only
B. C and D objects only
C. D and E objects only
D. S and E objects only

52 Assuming allocation succeeds, what is printed before scope exit?

class Box {
int *p;
public:
Box(int value) : p(new int(value)) {}
void set(int value) { *p = value; }
int get() const { return *p; }
};

Box a(5);
Box b = a;
b.set(9);
std::cout << a.get() << ' ' << b.get();

Classes and objects Hard
A. 9 9
B. 5 5
C. 5 9
D. The copy construction is rejected.

53 Suppose each constructor and destructor records its object's label. For the class below, which sequence is recorded when a D object is created and then destroyed?

struct D : B2, B1 {
M m2;
M m1;
D() : m1("m1"), m2("m2") { record("D"); }
~D() { record("~D"); }
};

Manager functions: constructors and destructors Hard
A. B2, B1, m2, m1, D, ~D, ~m2, ~m1, ~B1, ~B2
B. B2, B1, m1, m2, D, ~D, ~m2, ~m1, ~B1, ~B2
C. B1, B2, m2, m1, D, ~D, ~m1, ~m2, ~B2, ~B1
D. B2, B1, m2, m1, D, ~D, ~m1, ~m2, ~B1, ~B2

54 A collection must support insertion, removal of the most recently inserted value, and retrieval of the current minimum, all in worst-case time. Which design meets every requirement?

Introduction to data structures Hard
A. A sorted dynamic array shifted whenever a new value is inserted
B. A stack whose entries also store the minimum present at insertion time
C. An unsorted stack scanned whenever the current minimum is requested
D. A min-heap augmented with the time assigned to each inserted value

55 Which classification correctly describes all four data structures under their conventional implementations?

Types of data structures Hard
A. Array: linear noncontiguous; linked list: nonlinear dynamic; tree: linear hierarchical; graph: linear network
B. Array: nonlinear contiguous; linked list: linear contiguous; tree: linear hierarchical; graph: nonlinear network
C. Array: linear contiguous; linked list: linear noncontiguous; tree: nonlinear hierarchical; graph: nonlinear network
D. Array: nonlinear fixed; linked list: nonlinear contiguous; tree: linear recursive; graph: linear associative

56 Assume work() uses time and space. What are the time and auxiliary-space complexities of this code?

for (int i = 1; i <= n; ++i)
for (int j = i; j <= n; j += i)
work();

Time and space complexity analysis Hard
A. Time and space
B. Time and space
C. Time and space
D. Time and space

57 A static set of arbitrary keys must answer membership queries. The key universe is too large for direct addressing. Which approach uses extra space and achieves expected total time?

Time-space trade-off Hard
A. Keep the keys unsorted and scan the complete collection for each query.
B. Build a hash table and answer each query with expected constant-time lookup.
C. Sort the keys in place and answer each query using binary search.
D. Build a balanced search tree and use logarithmic-time lookup per query.

58 Define



Which asymptotic statement is correct?

Big-O notation Hard
A.
B.
C. but
D. but

59 Let for . Which claim is true?

Big-Omega notation Hard
A.
B.
C.
D.

60 For any fixed logarithm base greater than , determine the tight asymptotic bound of

Big-Theta notation Hard
A.
B.
C.
D.