i am a newbie to c++, as i wrote program to test how to pass array as the parameters in function, i wrote this little program:
#include <iostream>
using namespace std;
void pass_by_array(int a[]) {
int a_len = sizeof(a);
int e_len = sizeof(a[0]);
cout << "size of array in func: " << a_len << endl;
cout << "size of element in func: " << e_len << endl;
}
int main() {
int foo[] = {1, 8, 2, 7, 3, 6};
int a_len = sizeof(foo);
int e_len = sizeof(foo[0]);
cout << "size of array in main: " << a_len << endl;
cout << "size of element in main: " << e_len << endl;
pass_by_array(foo);
return 0;
}
here's the result i got:
size of array in main: 24
size of element in main: 4
size of array in func: 8
size of element in func: 4
so what the hell is going on there? the size of the array changed?!