I'm simply trying to get the size of an array passed as a parameter in a function, but I dont understand why the sizeof(k)/sizeof(k[0]) just returns one, when it works fine in the scope where it was declared, what am i missing here?
Heres the code:
#include <iostream>
using namespace std;
int fn(int k[]){
cout << "size in function :" << sizeof(*k) / sizeof(k[0]) << endl; //returns 1 for some reason
//cout << "size in function :" << end(k)-begin(k) << endl; // can't find begin-end fitting function?
int m = *max(&k[0], &k[sizeof(k)/sizeof(int)]);
return m;
}
int main()
{
int k[] = { 1,2,3,4,5,6,7 };
int s = size(k);
cout << "size :" << sizeof(k) / sizeof(k[0]) << endl;
cout << "max: " << fn(k);
return 0;
}