Item 6. Array Formal Arguments

Array formal arguments are problematic. The major surprise in store for the C/C++ novice is that there are no array formal arguments, because an array is passed as a pointer to its first element.

image

This automatic transformation from array to pointer is given the charming technical term “decay”; an array decays to a pointer to its first element. The same thing happens to functions, by the way. A function argument decays to a pointer to a function, but, unlike an array that loses its bound, a decaying function has the good sense to hold onto its argument and return types. (Note also the proper compile-time calculation ...

Get C++ Common Knowledge: Essential Intermediate Programming 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.