1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
void print2Darray_pointer(int *arr, int row, int col);
int main()
{
const int row { 3 };
const int col { 3 };
int arr[row][col] { { 1, 2, 3},
{ 4, 5, 6},
{ 7, 8, 9} };
print2Darray_pointer(reinterpret_cast<int*> (arr), row, col);
}
void print2Darray_pointer(int* arr, int r, int c)
{
for (int row { }; row < r; row++)
{
for (int col { }; col < c; col++)
{
std::cout << *((arr + row * c) + col) << ' ';
}
std::cout << '\n';
}
}
|