← All lectures

Lecture 20 · 30 min

Functions — Pass by Reference

Passing arguments by address using pointers so a function can modify the caller's variables; plus passing 1D and 2D arrays.

Pass by value vs referencePointer parametersSwappingPassing arrays
Slide 1 / 15

The limitation of pass-by-value

We saw that pass-by-value gives the function a copy. The original is safe — but what if you *want* the function to modify the original?

For example: a swap function needs to actually exchange the values of two variables in the caller. Pass-by-value won't work because it only swaps the copies.

← / → navigateF fullscreenEsc exit⌘K search