StudyGraph
Procedural Programming with C++ Remember it

Never forget how arrays pass to functions

Never forget what happens when you pass an array again

Lesson notes

Pass arrays to functions with their size and explain why changes affect the caller

Key points

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?
  1. The array is copied
  2. The pointer loses length
  3. 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