Programming foundations

Stage 3 · Lesson 8 of 9

What happens when you pass a value to a function

How computers run your code

This connects memory to code you write every day. When you pass a number to a , the function gets its own copy. When you pass a list or object in Python, JavaScript, Java or C#, the function gets a copy of the reference, so both names point to the same heap object.

This is sometimes called , and two names for one object is called . Appending inside the function changes the caller's list. But assigning a new list to the parameter does not affect the caller at all.

C++ copies the whole object by default, unless you pass a reference or a . Knowing which case applies explains most "my data changed" and "my change disappeared" bugs. It is also one of the things the milestone asks you to write up.

A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it

Resources for this stage

Start with· follow one of these

Keep handy

  • Quick explanations of OS basics like processes and memory when a lecture skips a step

Also worth your time

  • Everything from a key press to a rendered page; read it after this stage

Mark this stage as not done?