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).
Checking what this lesson needs for you…
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