Reference variables and passing by reference

Published

2023-08-05

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

Resources

  • References.pdf Note: Slides correct minor style errors that appear in video.

Comprehension check

  1. True or false? A reference variable is an identical copy of another variable.
  2. True or false? A variable and corresponding reference variable have exactly the same address in memory.
  3. True of false? The & operator in C++ is the logical AND.
  4. Which represents passing by reference? A or B?
    // Code A
    int* bologna = &turin;

    // Code B
    void someFunc(&roma) {
        roma ++;
    }

Answers: q / ǝslɐɟ / ǝnɹʇ / ǝslɐɟ

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.