6.2.4. Array Parameters
Arrays have two special properties that affect how we define and use functions that operate on arrays: We cannot copy an array (§ 3.5.1, p. 114), and when we use an array it is (usually) converted to a pointer (§ 3.5.3, p. 117). Because we cannot copy an array, we cannot pass an array by value. Because arrays are converted to pointers, when we pass an array to a function, we are actually passing a pointer to the array’s first element.
Even though we cannot pass an array by value, we can write a parameter that looks like an array:
Exercises Section 6.2.3
Exercise 6.16: The following function, although legal, is less useful than it might be. Identify and correct the limitation on this function:
bool is_empty(string& s) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access