True or false: For an int*, adding one always advances the pointer by exactly one byte.
7 Pointers and Dynamic Memory Online Quiz Questions
Use this free practice quiz with 20 questions to review 7 Pointers and Dynamic Memory, test your knowledge, and prepare for your next test or exam.
Select all operations that are valid for a null pointer without first making it point to an object.
- A
Compare a null pointer with
nullptr. - B
Dereference a null pointer to read an object.
- C
Copy a null pointer to another pointer.
- D
Assign
nullptrto a pointer.
Which expression correctly releases the storage allocated by int* data = new int[5];?
- A
delete data - B
delete[] data - C
free(data) - D
No release operation is needed.
Select all choices that the material identifies as preferable or useful alternatives to unmanaged raw-pointer ownership in appropriate situations.
- A
std::unique_ptrfor single ownership - B
A raw pointer with no documented owner
- C
std::shared_ptrwhen shared ownership is genuinely required - D
std::vectorfor a dynamic sequence of values
Which statement best explains the distinction between a raw array and a pointer to its first element?
- A
An array always points to dynamically allocated storage.
- B
A pointer always stores the number of elements it addresses.
- C
An array and a pointer are different types with different information.
- D
An array cannot be indexed with the subscript operator.
True or false: Returning &local from a function safely extends the lifetime of the local variable named local.
- A
True
- B
False
True or false: If a pointer refers to one position past the end of an array, dereferencing it is valid because the pointer is still within the array's range.
- A
True
- B
False
Given int value = 10; int* p = &value; *p = 25;, what integer value does evaluating *p produce afterward?
How should the declaration int* const fixed = nullptr; be described?
The expression new int(42) dynamically creates and returns a pointer to it.
Abandoning the original pointer to a dynamically allocated object without releasing the object causes .
Explain why declaring int* p; and then using p is unsafe. Give one appropriate initialization and describe the condition required before dereferencing the pointer.
Given the C++ code int value = 25; int* p = &value;, what does the expression *p evaluate to?
- A
The address of value
- B
The size of value in bytes
- C
The integer value stored in value
- D
A new integer allocated on the heap
Given int numbers[] = {10, 20, 30, 40}; int* p = numbers;, what value does *(p + 2) produce?
- A
10
- B
30
- C
40
- D
The expression is always invalid
Which statement correctly releases the dynamically allocated array created by int* data = new int[5]{};?
- A
delete data - B
free(data) - C
delete[] &data - D
delete[] data
What C++11 keyword should be used to initialize a pointer that intentionally points to no object?
What is wrong with returning &local from a function when local is an automatic local variable?
- A
The pointer is dangling because
localhas been destroyed - B
The pointer remains valid because returning an address extends the local variable's lifetime
- C
The pointer becomes null automatically
- D
The pointer safely refers to a newly allocated copy of
local
Which statement correctly distinguishes a raw array from a pointer to its first element?
- A
They are interchangeable types with identical storage and size information
- B
An array owns its elements and has a fixed size; a pointer stores an address without remembering the element count
- C
A pointer always owns the object it points to, but an array never owns its elements
- D
An array can be reseated to point to another object, but a pointer cannot
Given int numbers[4] = {10, 20, 30, 40}; int* first = &numbers[0]; int* last = &numbers[4];, what is the value of last - first?
Given the C++ code int score = 95; int* address = &score;, which statement best describes address?
- A
address contains the value 95, because it points to score
- B
address contains the address of score, whose exact numeric representation is implementation-dependent
- C
address contains the address of score as a portable integer byte offset
- D
address contains a copy of score that is independent of score
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.