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:
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) ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.