When a function has a specific-size array parameter, why is it replaced with a pointer?
问题 Given the following program, #include <iostream> using namespace std; void foo( char a[100] ) { cout << "foo() " << sizeof( a ) << endl; } int main() { char bar[100] = { 0 }; cout << "main() " << sizeof( bar ) << endl; foo( bar ); return 0; } outputs main() 100 foo() 4 Why is the array passed as a pointer to the first element? Is it a heritage from C? What does the standard say? Why is the strict type-safety of C++ dropped? 回答1: Yes it's inherited from C. The function: void foo ( char a[100]