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.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
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