Pointers and addresses

Published

2023-08-05

An introduction to memory addresses and pointers in C++. We show how memory is allocated, how addresses are referenced, and how to create and dereference a pointer.

Resources

Additional reading (optional)

Comprehension check:

Consider the following code:

double pi = 3.14159;
double* whatIsThis = π
  1. Describe the value of the variable whatIsThis.
  2. What will this print? std::cout << *whatIsThis << std::endl;.
  3. What symbol is used for the “address of” unary operator?
  4. True or false? The size of a pointer to a bool is smaller than the size of a pointer to a float.
  5. True or false? We call the process of getting the address of a variable “dereferencing”.

Answers: ǝslɐɟ / ǝslɐɟ / ⅋ / 6ϛƖㄣƖ˙Ɛ / ᴉd ǝlqɐᴉɹɐʌ ǝɥʇ ɟo ssǝɹppɐ ǝɥʇ sploɥ ʇI

Original author: Clayton Cafiero < [given name] DOT [surname] AT uvm DOT edu >

No generative AI was used in producing this material. This was written the old-fashioned way.

All materials copyright © 2020–2023, The University of Vermont. All rights reserved.