I've come across this:
Code:
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
class Chair
{
public:
vector<int> arrysize(int selectedArray[])
{
vector<int> result(2,0);
result[0] = sizeof(selectedArray);
result[1] = sizeof(selectedArray[0]);
return result;
}
};
int main(int argc, char *argv[])
{
Chair seat;
int sA[] = {2,4,7,3,7};
cout<<"sizeof(sA): "<<sizeof(sA)<<endl;
cout<<"sizeof(sA[0]): "<<sizeof(sA[0])<<endl;
cout<<"sizeof(sA) using arrysize(): "<<seat.arrysize(sA)[0]<<endl;
cout<<"sizeof(sA[0]) using arrysize(): "<<seat.arrysize(sA)[1]<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Now this pops out the following results:
sizeof(sA): 20
sizeof(sA)[0]): 4
sizeof(sA) using arrysize(): 4
sizeof(sA[0]) using arrysize(): 4
My question is why is this giving different results when i get the size of the array through the function as opposed to getting the size of the array within the main loop?