I understand the implicit conversion into a pointer. Someone suggested something like this today in some other question:
#include <iostream>
void printArray(int (&a)[5]) {
for (int i : a) {
std::cout << i << " ";
}
}
int main() {
int a[] = { 1, 2, 3, 4, 5 };
printArray(a);
}
Questions
Is this the only and the best way of passing an entire array to a function rather than just the pointer to the first element (though inefficient)?
However, if that function were to be written below the main function, what would the function prototype be?
Also, if I were to only use an enhanced for loop to iterate through the elements of an array passed to a function, is there any better way?