C++20 sections · 1024 units
Open in Course

Passing Size Separately

Why you need a size parameter

Since arrays decay and lose size, pass the size as a separate parameter. Write void process(int arr[], int size) with both array and length. The caller provides both values. This pattern appears everywhere in C-style code.

Functions that work with arrays take two parameters. The size lets you loop correctly with for (int i = 0; i < size; i++) inside. The alternative is sentinel values (like null-terminated strings) or fixed compile-time sizes.

But explicit size parameters are clearer and more flexible for general array work.