Free Practice Quiz Question List

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.

20 questions
01
True or false
1 point

True or false: For an int*, adding one always advances the pointer by exactly one byte.

  1. A

    True

  2. B

    False

02
Choose all
1 point

Select all operations that are valid for a null pointer without first making it point to an object.

  1. A

    Compare a null pointer with nullptr.

  2. B

    Dereference a null pointer to read an object.

  3. C

    Copy a null pointer to another pointer.

  4. D

    Assign nullptr to a pointer.

03
Choose one
1 point

Which expression correctly releases the storage allocated by int* data = new int[5];?

  1. A

    delete data

  2. B

    delete[] data

  3. C

    free(data)

  4. D

    No release operation is needed.

04
Choose all
1 point

Select all choices that the material identifies as preferable or useful alternatives to unmanaged raw-pointer ownership in appropriate situations.

  1. A

    std::unique_ptr for single ownership

  2. B

    A raw pointer with no documented owner

  3. C

    std::shared_ptr when shared ownership is genuinely required

  4. D

    std::vector for a dynamic sequence of values

05
Choose one
1 point

Which statement best explains the distinction between a raw array and a pointer to its first element?

  1. A

    An array always points to dynamically allocated storage.

  2. B

    A pointer always stores the number of elements it addresses.

  3. C

    An array and a pointer are different types with different information.

  4. D

    An array cannot be indexed with the subscript operator.

06
True or false
1 point

True or false: Returning &local from a function safely extends the lifetime of the local variable named local.

  1. A

    True

  2. B

    False

07
True or false
1 point

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.

  1. A

    True

  2. B

    False

08
Written response
1 point

Given int value = 10; int* p = &value; *p = 25;, what integer value does evaluating *p produce afterward?

09
Written response
1 point

How should the declaration int* const fixed = nullptr; be described?

10
Fill in the blank
1 point

The expression new int(42) dynamically creates and returns a pointer to it.

11
Fill in the blank
1 point

Abandoning the original pointer to a dynamically allocated object without releasing the object causes .

12
Open ended
1 point

Explain why declaring int* p; and then using p is unsafe. Give one appropriate initialization and describe the condition required before dereferencing the pointer.

13
Choose one
1 point

Given the C++ code int value = 25; int* p = &value;, what does the expression *p evaluate to?

  1. A

    The address of value

  2. B

    The size of value in bytes

  3. C

    The integer value stored in value

  4. D

    A new integer allocated on the heap

14
Choose one
1 point

Given int numbers[] = {10, 20, 30, 40}; int* p = numbers;, what value does *(p + 2) produce?

  1. A

    10

  2. B

    30

  3. C

    40

  4. D

    The expression is always invalid

15
Choose one
1 point

Which statement correctly releases the dynamically allocated array created by int* data = new int[5]{};?

  1. A

    delete data

  2. B

    free(data)

  3. C

    delete[] &data

  4. D

    delete[] data

16
Written response
1 point

What C++11 keyword should be used to initialize a pointer that intentionally points to no object?

17
Choose one
1 point

What is wrong with returning &local from a function when local is an automatic local variable?

  1. A

    The pointer is dangling because local has been destroyed

  2. B

    The pointer remains valid because returning an address extends the local variable's lifetime

  3. C

    The pointer becomes null automatically

  4. D

    The pointer safely refers to a newly allocated copy of local

18
Choose one
1 point

Which statement correctly distinguishes a raw array from a pointer to its first element?

  1. A

    They are interchangeable types with identical storage and size information

  2. B

    An array owns its elements and has a fixed size; a pointer stores an address without remembering the element count

  3. C

    A pointer always owns the object it points to, but an array never owns its elements

  4. D

    An array can be reseated to point to another object, but a pointer cannot

19
Written response
1 point

Given int numbers[4] = {10, 20, 30, 40}; int* first = &numbers[0]; int* last = &numbers[4];, what is the value of last - first?

20
Choose one
1 point

Given the C++ code int score = 95; int* address = &score;, which statement best describes address?

  1. A

    address contains the value 95, because it points to score

  2. B

    address contains the address of score, whose exact numeric representation is implementation-dependent

  3. C

    address contains the address of score as a portable integer byte offset

  4. D

    address contains a copy of score that is independent of score