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. Conditional statements
B. Arithmetic operators
C. Built-in integers
D. Classes and objects

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

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

3 What is a variable in a program?

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

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

Constants Easy
A. return
B. const
C. static
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. sizeof
B. scanf
C. cin
D. cout

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

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

7 What does a function declaration tell the compiler?

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

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

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

9 What is recursion?

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

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

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

11 Which keyword defines a structure in C++?

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

12 What is an object in C++?

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

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

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

14 What is the main purpose of a data structure?

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

15 Which of the following is a linear data structure?

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

16 What does time complexity describe?

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

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 exact memory address
B. An asymptotic lower bound
C. An exact machine runtime
D. An asymptotic upper bound

19 What does Big-Omega notation commonly express?

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

20 What does indicate about an algorithm's growth?

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

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. Operator precedence
C. Function overloading
D. Function overriding

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

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

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

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

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

Constants Medium
A. p = &b;
B. (*p)++;
C. *p = 3;
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 %f", &n, &x); and cin << n << x;
B. scanf("%d %lf", n, x); and cin >> x >> n;
C. scanf("%d %lf", &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. 21
B. 4
C. 16
D. 9

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. 7
B. 5
C. 2
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. 5 3
C. 3 5
D. 3 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. 12
B. 7
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. Derived::show()
B. Neither implementation
C. Base::show()
D. Both implementations

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. Both data members are private
C. S::x is private and C::x is public
D. S::x is public and C::x is 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 2
C. 3 and 3
D. 2 and 1

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 Derived, Base, Member; destroy Member, Base, Derived
B. Construct Member, Base, Derived; destroy Derived, Base, Member
C. Construct Base, Derived, Member; destroy Member, Derived, Base
D. Construct Base, Member, Derived; destroy Derived, Member, Base

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. Binary heap
B. Stack
C. Queue
D. Hash table

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

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

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. Recalculate results on demand
B. Replace iteration with recursion
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 requires an explicit cast of the result from malloc.
B. It is valid C but ill-formed C++ because C++ does not implicitly convert void * to int *.
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. 0, because i is converted to a large unsigned value before comparison.
B. The result is undefined because negative integers cannot be converted to unsigned.
C. 0, because every comparison between signed and unsigned values is false.
D. 1, because the signed value -1 is numerically smaller than unsigned 1.

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 3 1
B. 3 4 4
C. 3 4 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 = 3;
D. p = &b;

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 2, n is 42, and c contains the newline.
B. r is 1, n is 4, and c contains the character 2.
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. void f(int *); and void f(const int *);
B. void f(int); and void f(const int);
C. int f(int); and double f(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. 12
B. 18
C. The call is ill-formed.
D. 6

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. Derived
B. The behavior is undefined.
C. Base
D. BaseDerived

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. C and D objects only
B. S and E objects only
C. D and E objects only
D. S and D 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. 5 5
B. 5 9
C. The copy construction is rejected.
D. 9 9

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. B1, B2, m2, m1, D, ~D, ~m1, ~m2, ~B2, ~B1
B. B2, B1, m2, m1, D, ~D, ~m1, ~m2, ~B1, ~B2
C. B2, B1, m2, m1, D, ~D, ~m2, ~m1, ~B1, ~B2
D. B2, B1, m1, m2, D, ~D, ~m2, ~m1, ~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 min-heap augmented with the time assigned to each inserted value
B. An unsorted stack scanned whenever the current minimum is requested
C. A stack whose entries also store the minimum present at insertion time
D. A sorted dynamic array shifted whenever a new value is inserted

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

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

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. Build a balanced search tree and use logarithmic-time lookup per 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. Keep the keys unsorted and scan the complete collection for each query.

58 Define



Which asymptotic statement is correct?

Big-O notation Hard
A.
B. but
C.
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.