pass array as reference c++ code example
Example 1: array as parameter c++
void myFunction(int param[]) {
.
.
.
}
Example 2: passing array to function c++ pointer
void generateArray(int *a, int si)
{
for (int j = 0; j < si; j++)
a[j] = rand() % 9;
}
int main()
{
const int size=5;
int a[size];
generateArray(a, size);
return 0;
}
Example 3: array reference argument
template<typename T, size_t N>
void foo(T (&bar)[N])
{
// use N here
}