I had the online coding interview today and I really struggled while trying to calculate the size of the array. Could you please help me with how can I measure the sizeof array here? I tried my best but no luck please help here.
#include<iostream>
#include<map>
#include<vector>
using namespace std;
void arraysize(int* a) {
cout << "size1: "<<sizeof(a) << endl;
cout << "size2: " << sizeof(a[0]) << endl;;
}
int main()
{
int array1[] = { 1,2,3,4,5,6,7,8 };
arraysize(array1);
return 0;
}
Result: size1: 4 size2: 4
arraysize's signature? If so, if you make a template-function that acceptsstd::arraythen it's straightforward.arraysizecannot determine the size ofarray1from the information available to it in the code shown. What was the specific question you were asked? If it was how to change the code to make the array size available, then there are several alternatives.