Hello, everyone. I found sizeof(array) only works correctly in main() function.
Could you please tell me why?
-------------------------------------------------
#include <iostream>
using namespace std;
int f(const int array[]){
cout << sizeof(array) << endl;
//cout << array[index] << endl; //1
}
int main(){
int array[5] = {3,4,9,1,5};
cout << sizeof(array) << endl;
f(array);
return 0;
}
The output is:
20
4
------------------------------------------------
but if I print the whole array in f() (remove comment at 1),
the array content can be still printed out.