For example the function can be defined the following way
const size_t N = 3;
void display( const int ( &MatA )[N][N] )
{
for ( size_t i = 0; i < N; i++ )
{
for ( size_t j = 0; j < N; j++ ) std::cout << MatA[i][j] << " ";
std::cout << std::endl;
}
}
The other way is the following
const size_t N = 3;
void display( const int ( *MatA )[N], size_t n )
{
for ( size_t i = 0; i < n; i++ )
{
for ( size_t j = 0; j < N; j++ ) std::cout << MatA[i][j] << " ";
std::cout << std::endl;
}
}
The functions can be called as
#include <iostream>
const size_t N = 3;
// the function definitions
int main()
{
int a[N][N] = {};
// some code to fill the matrix
display( a );
display( a, N );
}
And at last you can use the approach suggested in comments to the post by @boycy though as for me then I do not like this approach. For example
#include <iostream>
const size_t N = 3;
void display( const int **MatA, size_t m, size_t n )
{
for ( size_t i = 0; i < m * n; i++ )
{
std::cout << MatA[i] << " ";
if ( ( i + 1 ) % n == 0 ) std::cout << std::endl;
}
}
int main()
{
int a[N][N] = {};
// some code to fill the matrix
display( reinterpret_cast<const int **>( a ), N, N );
}