I\'m trying to learn more about arrays since I\'m new to programming. So I was playing with different parts of code and was trying to learn about three things, sizeof(
What you've encountered was array-to-pointer conversion, a C language feature inherited by C++. There's a detailed C++-faq post about this: How do I use arrays in C++?
Since you're using C++, you could pass the array by reference:
template
void arrayprint(int (&inarray)[N])
{
for (int n_i = 0 ; n_i < (sizeof(inarray) / sizeof(int)) ; n_i++)
cout << inarray[n_i] << endl;
}
although in that case the sizeof calculation is redundant:
template
void arrayprint(int (&inarray)[N])
{
for (size_t n_i = 0 ; n_i < N ; n_i++)
cout << inarray[n_i] << '\n';
}
And, as already mentioned, if your goal is not specifically to pass a C array to a function, but to pass a container or a sequence of values, consider using std::vector and other containers and/or iterators.