Вот обычный способ. Вы можете использовать любую версию функции "f":
#include <cstdlib>
const size_t cols = 10; // You can hardcode this below if you want
// Can only be called if you know "cols" at compile-time
void f(int pArray[][cols], size_t rows)
{
for(size_t i = 0; i < rows; ++i)
{
for(size_t j = 0; j < cols; ++j)
{
pArray[i][j] = 1;
}
}
}
// Use this if you don't know "cols" at compile-time (good for any arbitrary 2D array)
void f(int *pArray, size_t rows, size_t cols)
{
for(size_t i = 0; i < rows; ++i)
{
const size_t RowOffset = (i * cols);
for(size_t j = 0; j < cols; ++j)
{
pArray[RowOffset + j] = 1;
}
}
}
int main()
{
int array[][cols]= {{ 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 },
{ 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 },
{ 105, 110, 115, 120, 125, 130, 135, 140, 145, 150 },
{ 155, 160, 165, 170, 175, 180, 185, 190, 195, 200 },
{ 205, 210, 220, 225, 230, 235, 240, 245, 250, 255}};
const size_t rows = sizeof(array) / sizeof(array[0]); // 5 in this example but you can hardcode it if you want
f(array, rows);
f(array[0], rows, cols);
return 0;
}