Which C++ operator produces a pointer to an object or function, as in int* p = &score;?
07 Pointers and Memory Basics Online Quiz Questions
Use this free practice quiz with 20 questions to review 07 Pointers and Memory Basics, test your knowledge, and prepare for your next test or exam.
True or false: A pointer automatically keeps the object it identifies alive for as long as the pointer exists.
- A
True
- B
False
What C++ literal should you use to initialize an int* when it should point to no object?
In the declaration int* first, second;, which variable is the pointer to int? Answer the variable name: .
Given int values[3] = {4, 8, 12};, what value does *(values + 2) produce?
- A
4
- B
8
- C
12
- D
The address of
values[2]
Select all statements that are true for the declarations const int* p1 = &number; and int* const p2 = &number;.
- A
p1 = &other;is allowed. - B
*p1 = 11;is allowed. - C
p2 = &other;is not allowed. - D
*p2 = 11;is not allowed.
True or false: If end points one position past the end of an array, evaluating *end is permitted because end is a valid pointer value.
- A
True
- B
False
Given int values[] = {10, 20, 30, 40};, what number of elements is represented by &values[4] - &values[0]?
Complete the statement with the parameter form that allows a function to change the caller's pointer itself: In ordinary C++, pass a .
What does int (*operation)(int) = square; declare?
- A
A pointer to an
intobject - B
A function returning an
int*and accepting no arguments - C
A reference to a function returning
int - D
A pointer to a function accepting an
intand returning anint
Select all cases in which dereferencing a pointer is described as unsafe or undefined by the material.
- A
A null pointer
- B
A dangling pointer
- C
A pointer that is non-null and points to a live, correctly aligned object
- D
A pointer outside the permitted object or array range
Given int values[3]; int* p = values;, which statement correctly compares sizeof(values) and sizeof(p)?
- A
sizeof(values)is always equal tosizeof(p). - B
pretains the array length in its type. - C
sizeof(values)measures all threeintelements, whilesizeof(p)measures a pointer. - D
The array is converted to a pointer even inside
sizeof(values).
Consider int* bad_pointer() { int local = 42; return &local; }. Explain why the returned pointer is unsafe, and describe at least one way to redesign the function so that the result remains valid.
Given int values[] = {10, 20, 30, 40}; int* p = values;, what integer does *(p + 2) produce?
Consider the declaration const int* p1 = &number;. Which statement correctly describes what can be changed through p1?
- A
p1cannot point to another object, but the pointed-to integer can be changed throughp1. - B
p1can point to another object, but the pointed-to integer cannot be changed throughp1. - C
Neither
p1nor the pointed-to integer can ever change. - D
p1is an ordinaryintvariable, not a pointer.
Given int values[] = {10, 20, 30, 40}; int* p = values;, what value is produced by *(p + 2)?
- A
10 - B
20 - C
30 - D
Undefined behavior, because adding to an array pointer is never allowed.
In the declaration int sum(const int values[], std::size_t count), how is the values parameter treated when the function is compiled?
- A
The parameter is adjusted to
int* values, so the function does not receive the array length automatically. - B
The parameter remains an array type and carries its length with it.
- C
The parameter is adjusted to
int** values. - D
The function receives a complete copy of every array element.
Inside void redirect(int* p, int* replacement), what is the effect of the statement p = replacement; on a pointer passed by the caller?
- A
Assigning
p = replacementalways changes the caller's pointer. - B
The function cannot read or modify the caller's object through
p. - C
The pointer parameter is passed by reference automatically.
- D
Assigning
p = replacementchanges only the local copy of the pointer.
True or false: A pointer one position past the end of an array may be used as a loop boundary, but it must not be dereferenced.
- A
True
- B
False
Given int values[] = {10, 20, 30, 40}; int* first = &values[0]; int* last = &values[4];, what is the value of last - first?
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.