Module 7 · Functions, Scope and Storage Classes
Pass by Value: What a Function Really Gets
Free with an accountReading
Bob's game shows two scores, and the higher one must come first. He writes a function called swap that trades two numbers. When the scores are the wrong way round, he calls swap(x, y).
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 Value: What a Function Really Gets
- A call copies the value
- Bob's swap swaps nothing
- The honest fix: return the new value
- What GCC 12 says about a changed parameter
- Parameters are ordinary locals
- const on a parameter: a promise
- Why sqrt(x) leaves x alone