void printElements(int(arr)[4]) // option 1
//void printElements(int(&arr)[4]) // option 2
{
int length( sizeof(arr) / sizeof(arr[0]) );
std:: cout <<"length is "<< length << std::endl;
for (int i( 0 ); i < length; ++i)
{
std::cout << arr[i] << std::endl;
}
}
with the main function
int main() {
int arr[]{99, 20, 14, 80};
printElements(arr);
}
As listed, two options: one is void printElements(int(arr)[4])
, another is void printElements(int(&arr)[4])
. But the first one will cout
the size of the array is 2. The second says the size of the array is 4. Why is the difference?