The output of the following function is “int *”, which means the formal parameter is converted to a integer pointer. Is there any necessary reason for this design? Why can’t we reserve the array type?
// the output is "int *"
#include<typeinfo>
void Func(int ar[5])
{
printf("%s\n", typeid(ar).name();
}
int main()
{
int ar[5];
Func(ar);
return 0;
}
This is historical baggage from C. Supposedly 1 this was convenience as you can’t pass arrays by-value anyway.
If you want to preserve the type, you can use a references or pointers:
Or using template functions to accept an arbitrarily sized array: