Module 11 · Pointers and Memory
Pass by Reference: Letting a Function Change Your Variable
Free with an accountReading
Module 7 lesson 3 ended with Bob's swap trading two copies while main's numbers sat still. Lessons 01 and 02 gave you the missing piece: an address, and a pointer that holds one. Today Bob adds a few stars and two ampersands, and his swap finally swaps. Then the same trick gets two results out of one call.
Checking what this lesson needs for you…
What is inside Pass by Reference: Letting a Function Change Your Variable
- Bob's swap, with addresses
- The parameter is still a copy, a copy of an address
- Two results from one call: out-parameters
- scanf has worked this way since Module 3
- A status return, the result through a pointer
- The convention, and the caller's ampersands