Learn C Programming

Lesson 4 of 10 · Pointers and Memory

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

  1. Bob's swap, with addresses
  2. The parameter is still a copy, a copy of an address
  3. Two results from one call: out-parameters
  4. scanf has worked this way since Module 3
  5. A status return, the result through a pointer
  6. The convention, and the caller's ampersands