Reference variables and passing by reference
Demonstration and explanation of reference variables and passing by reference. We also revisit our lecturer class, going over the places where we passed by reference without much explanation earlier.
Since we’ve ended this video by showing where pass by reference occurred in our lecturer class, it would be advisable to go back to the source code for that module and see for yourself.
Additional reading
- Reference declarations: https://en.cppreference.com/w/cpp/language/reference
- When to pass by value, reference, and pointer: https://www.cplusplus.com/articles/z6vU7k9E/
Resources
- References.pdf Note: Slides correct minor style errors that appear in video.
Comprehension check
- True or false? A reference variable is an identical copy of another variable.
- True or false? A variable and corresponding reference variable have exactly the same address in memory.
- True of false? The
&
operator in C++ is the logical AND. - Which represents passing by reference? A or B?
// Code A
int* bologna = &turin;
// Code B
void someFunc(&roma) {
++;
roma }
Answers: q / ǝslɐɟ / ǝnɹʇ / ǝslɐɟ
Copyright © 2023–2025 Clayton Cafiero
No generative AI was used in producing this material. This was written the old-fashioned way.