Procedural Programming with C++
Remember it
Never forget how arrays pass to functions
Never forget what happens when you pass an array again
Quick check · tap an answer to continue
Lesson notes
Pass arrays to functions with their size and explain why changes affect the caller
Key points
- Decay / Array decay: Passing scores turns the array name into a pointer to its first element.
- Sends / Send the size: The pointer forgets the length, so always pass n alongside the array.
- Pointers / Changes persist: No copy is made, so doubleAll changes the caller's scores in main.
- Constants / const parameter: Write const int arr[] when a function should only read, never modify.
Takeaway: Arrays decay to pointers: pass the size, use const to protect.
Quick check: Why must a function taking int arr[] also receive the array's size?
- The array is copied
- The pointer loses length
- Size sets the type
The array decays to a pointer, which carries no information about element count.
array decayconst parameter
Lessons like this, for your syllabus.
Short narrated study videos written for your course, level and exam. Free to start.
Get lessons for your own syllabus