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
- Quiz
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
- Study guide
03 — Programming Fundamentals: Python Essentials
A progressive guide to Python programming fundamentals, connecting values, expressions, control flow, functions, input, output, and an integrated grade calculator.
- Flashcards
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
- Quiz
3 Conditional Control Flow
A medium-difficulty quiz on Python conditional control flow, including branching, comparison and logical operators, truthiness, short-circuit evaluation, nesting, and common syntax mistakes.
- Study guide
3 CPU Architecture
Learn how registers, the ALU, datapath connections, and control logic work together to fetch and execute CPU instructions.
- Study guide
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.
Programming in Java - CS 102Updated - Study guide
05 — Data Structures: Concepts, Operations, and Trade-Offs
A structured guide to the main data structures, their operations, efficiency trade-offs, representations, and practical selection criteria.
- Quiz
6 Interfaces and Abstractions
A medium-difficulty quiz on interfaces, abstractions, abstract classes, polymorphism, dependency direction, dependency injection, and contract design. The quiz includes 12 required candidates and 2 additional alternate candidates.
- Study guide
07 — Efficiency and Computational Complexity
A progressive guide to measuring algorithmic time and memory requirements, interpreting asymptotic bounds, analyzing common code patterns, and balancing performance trade-offs.
- Study guide
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.
- Flashcards
08 — Discrete Mathematics for Computer Science
A focused review of propositional logic, quantifiers, sets, relations, functions, and foundational proof methods in discrete mathematics for computer science.
- Study guide
10 — Data, Systems, and Applications
A progression through how data is organized, searched, exposed through software interfaces, and managed through abstraction layers in modern computer systems.