PRACTICE • LEARN • GROW
Module 4 Final Quiz: Pointers, References & Memory MCQs
Solve topic-wise placement questions and improve your skills.
Module 4 Final Quiz: Pointers, References & Memory Progress
0 of 12 completed
0%
Topic Track
You are viewing MCQs in preview mode. Log in to select options, submit answers, and track your progress.
Log In to Answer
1
What does the unary operator '&' do when placed before a variable name (e.g. &x)?
A.
Performs bitwise AND
B.
Retrieves the memory address where x is stored
C.
Dereferences the variable
D.
Deletes the variable from memory
Explanation & Key
Correct Answer:
2
What does dereferencing a pointer using the '*' operator do (e.g. *p)?
A.
Multiplies the address by 2
B.
Accesses the value stored at the memory address held in pointer p
C.
Allocates a new pointer
D.
Frees the memory
Explanation & Key
Correct Answer:
3
What are two fundamental differences between a C++ reference and a pointer?
A.
Pointers cannot be null; references can be null
B.
A reference cannot be null and cannot be reseated to another variable once bound; a pointer can be null and reassigned to point elsewhere
C.
References require manual deletion with delete; pointers do not
D.
Pointers are only allowed in C; references are only allowed in Python
Explanation & Key
Correct Answer:
4
What is the output of the following snippet?
int a = 5;
int& ref = a;
ref = 20;
cout << a;
A.
5
B.
20
C.
Garbage memory
D.
Compilation Error
Explanation & Key
Correct Answer:
5
Which memory region is automatically managed by the compiler and deallocated immediately upon function return?
A.
The Heap
B.
The Stack
C.
The Data segment
D.
The Virtual memory page
Explanation & Key
Correct Answer:
6
What happens if a program allocates heap memory with 'new' but never calls 'delete'?
A.
The compiler frees it automatically at the end of the function
B.
A memory leak occurs: the allocated RAM remains reserved and inaccessible until the process terminates
C.
The program throws a NullPointerException
D.
The stack overflows immediately
Explanation & Key
Correct Answer:
7
What is the consequence of freeing an array allocated with 'new int[100]' using 'delete p' instead of 'delete[] p'?
A.
All 100 elements are cleanly freed
B.
Undefined Behavior occurs: only the first element's destructor may run and the heap manager is corrupted
C.
The code will not compile
D.
Memory is converted into a vector
Explanation & Key
Correct Answer:
8
Which smart pointer from enforces exclusive, single ownership of a heap object?
A.
std::shared_ptr
B.
std::weak_ptr
C.
std::unique_ptr
D.
std::auto_ptr
Explanation & Key
Correct Answer:
9
How does std::shared_ptr know when to delete its underlying heap object?
A.
By inspecting the stack frame count
B.
By maintaining a reference count in a control block, destroying the object when the count reaches zero
C.
Through periodic background garbage collection runs
D.
When the operating system sends an interrupt signal
Explanation & Key
Correct Answer:
10
What critical problem does std::weak_ptr solve?
A.
It makes pointers faster than raw pointers
B.
It breaks circular reference cycles between shared_ptrs that would otherwise prevent reference counts from ever reaching zero
C.
It allows pointers to be stored in ROM
D.
It converts pointers to integers
Explanation & Key
Correct Answer:
11
What is the recommended modern C++ way to instantiate a unique_ptr (C++14)?
A.
new unique_ptr(10)
B.
std::make_unique(10)
C.
malloc(sizeof(unique_ptr))
D.
unique_ptr::create(10)
Explanation & Key
Correct Answer:
12
What is the output of the following pointer arithmetic snippet?
int arr[] = {10, 20, 30};
int* p = arr;
p++;
cout << *p;
A.
10
B.
11
C.
20
D.
30
Explanation & Key
Correct Answer:
Question Palette
Answered
Current
Not Attempted
Wrong