Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

Which C++ operator produces a pointer to an object or function, as in int* p = &score;?

  1. A

    The dereference operator *

  2. B

    The address-of operator &

  3. C

    The null-pointer literal nullptr

  4. D

    The pointer-subtraction operator -

02
True or false
1 point

True or false: A pointer automatically keeps the object it identifies alive for as long as the pointer exists.

  1. A

    True

  2. B

    False

03
Written response
1 point

What C++ literal should you use to initialize an int* when it should point to no object?

04
Fill in the blank
1 point

In the declaration int* first, second;, which variable is the pointer to int? Answer the variable name: .

05
Choose one
1 point

Given int values[3] = {4, 8, 12};, what value does *(values + 2) produce?

  1. A

    4

  2. B

    8

  3. C

    12

  4. D

    The address of values[2]

06
Choose all
1 point

Select all statements that are true for the declarations const int* p1 = &number; and int* const p2 = &number;.

  1. A

    p1 = &other; is allowed.

  2. B

    *p1 = 11; is allowed.

  3. C

    p2 = &other; is not allowed.

  4. D

    *p2 = 11; is not allowed.

07
True or false
1 point

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.

  1. A

    True

  2. B

    False

08
Written response
1 point

Given int values[] = {10, 20, 30, 40};, what number of elements is represented by &values[4] - &values[0]?

09
Fill in the blank
1 point

Complete the statement with the parameter form that allows a function to change the caller's pointer itself: In ordinary C++, pass a .

10
Choose one
1 point

What does int (*operation)(int) = square; declare?

  1. A

    A pointer to an int object

  2. B

    A function returning an int* and accepting no arguments

  3. C

    A reference to a function returning int

  4. D

    A pointer to a function accepting an int and returning an int

11
Choose all
1 point

Select all cases in which dereferencing a pointer is described as unsafe or undefined by the material.

  1. A

    A null pointer

  2. B

    A dangling pointer

  3. C

    A pointer that is non-null and points to a live, correctly aligned object

  4. D

    A pointer outside the permitted object or array range

12
Choose one
1 point

Given int values[3]; int* p = values;, which statement correctly compares sizeof(values) and sizeof(p)?

  1. A

    sizeof(values) is always equal to sizeof(p).

  2. B

    p retains the array length in its type.

  3. C

    sizeof(values) measures all three int elements, while sizeof(p) measures a pointer.

  4. D

    The array is converted to a pointer even inside sizeof(values).

13
Open ended
1 point

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.

14
Written response
1 point

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

15
Choose one
1 point

Consider the declaration const int* p1 = &number;. Which statement correctly describes what can be changed through p1?

  1. A

    p1 cannot point to another object, but the pointed-to integer can be changed through p1.

  2. B

    p1 can point to another object, but the pointed-to integer cannot be changed through p1.

  3. C

    Neither p1 nor the pointed-to integer can ever change.

  4. D

    p1 is an ordinary int variable, not a pointer.

16
Choose one
1 point

Given int values[] = {10, 20, 30, 40}; int* p = values;, what value is produced by *(p + 2)?

  1. A

    10

  2. B

    20

  3. C

    30

  4. D

    Undefined behavior, because adding to an array pointer is never allowed.

17
Choose one
1 point

In the declaration int sum(const int values[], std::size_t count), how is the values parameter treated when the function is compiled?

  1. A

    The parameter is adjusted to int* values, so the function does not receive the array length automatically.

  2. B

    The parameter remains an array type and carries its length with it.

  3. C

    The parameter is adjusted to int** values.

  4. D

    The function receives a complete copy of every array element.

18
Choose one
1 point

Inside void redirect(int* p, int* replacement), what is the effect of the statement p = replacement; on a pointer passed by the caller?

  1. A

    Assigning p = replacement always changes the caller's pointer.

  2. B

    The function cannot read or modify the caller's object through p.

  3. C

    The pointer parameter is passed by reference automatically.

  4. D

    Assigning p = replacement changes only the local copy of the pointer.

19
True or false
1 point

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.

  1. A

    True

  2. B

    False

20
Written response
1 point

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