Declaring Built-In Array Parameters

You can declare a built-in array parameter in a function header, as follows:

int sumElements( const int values[], const size_t numberOfElements )

which indicates that the function’s first argument should be a one-dimensional built-in array of ints that should not be modified by the function. Unlike array objects, built-in arrays don’t know their own size, so a function that processes a built-in array should have parameters to receive both the built-in array and its size.

The preceding header can also be written as:

int sumElements( const int *values, const size_t numberOfElements )

The compiler does not differentiate between a function that receives a pointer and a function that receives a built-in array. ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.