Let's consider the following code:
#include <iostream>
using namespace std;
void foo(int * arr)
{
cout << sizeof(arr) << endl;
}
int main()
{
int arr[3] = {1, 2, 3};
cout << sizeof(arr) << endl;
foo(arr);
}
Since array name decay into pointer to its first element, why does sizeof(arr) inside foo() returns 8 instead of 4?
std::vectororstd::arraydepending on your use case. Otherwise it is canonical in C APIs to pass two params per array: first the pointer to the array, second the number of elements.