sizeof(array) returns different values in main() and user defined functions

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.

Can anyone explain the reason behind it?

Thank you very much.
Last edited on
Answered in general c++ forum.
Thanks for telling me. :-)
Topic archived. No new replies allowed.