Pointers and addresses
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
- Pointers_and_addresses.pdf. Note: Slides include corrections to minor style errors in code presented in video.)
Additional reading (optional)
- Stroustrup, Bjarne, Programming: Principles and Practice Using C++, Section 17.3 Memory, addresses, and pointers. Pearson, 2009.
- http://www.cplusplus.com/doc/tutorial/pointers/
- https://en.wikipedia.org/wiki/Memory_address
Comprehension check:
Consider the following code:
double pi = 3.14159;
double* whatIsThis = π
- Describe the value of the variable
whatIsThis
. - What will this print?
std::cout << *whatIsThis << std::endl;
. - What symbol is used for the “address of” unary operator?
- True or false? The size of a pointer to a bool is smaller than the size of a pointer to a float.
- 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.