C++ support for multidimension arrays is done through libraries (eg boost). Without classes it really only understands 1D arrays, particularly when you are using pointers, which C/C++ really sees as just a pointer to the first element of the array. To get your example to work without classes you need to define a type that holds one row and then create an array of that type, which you can assign values to as you show.
#include <iostream>
#include <cstdlib>
using namespace std;
int main () {
typedef int row_t[5];
row_t *arr = new row_t[4] {{3, 6, 9, 23, 16},
{24, 12, 9, 13, 5},
{37, 19, 43, 17, 11},
{71, 32, 8, 4, 7}};
cout<< arr[1][3] << endl<< endl;
int *x = new int;
*x = arr [2][1];
cout<< x<< endl;
cout<< *x<< endl << endl;
*x = arr [0][3];
cout<< x<< endl;
cout<< *x<< endl;
delete x;
delete [] arr;
return 0;
}
Alternatively you can project the 2D array onto a 1D array as:
#include <iostream>
#include <cstdlib>
using namespace std;
int main () {
int *arr = new int[20] {3, 6, 9, 23, 16,
24, 12, 9, 13, 5,
37, 19, 43, 17, 11,
71, 32, 8, 4, 7};
cout<< arr[5*1+3] << endl<< endl;
int *x = new int;
*x = arr [5*2+1];
cout<< x<< endl;
cout<< *x<< endl << endl;
*x = arr [5*0+3];
cout<< x<< endl;
cout<< *x<< endl;
delete x;
delete [] arr;
return 0;
}
To get 2D indexing with dynamic data use something like boost::multi_array
#include <iostream>
#include <boost/multi_array.hpp>
using namespace std;
int main () {
boost::multi_array< int, 2 >arr(boost::extents[4][5]);
int tmp[] { 3, 6, 9, 23, 16,
24, 12, 9, 13, 5,
37, 19, 43, 17, 11,
71, 32, 8, 4, 7 };
arr = boost::multi_array_ref< int, 2 >( &tmp[0], boost::extents[4][5] );
cout<< arr [1][3]<< endl << endl;
int *x = new int;
*x = arr [2][1];
cout<< x<< endl;
cout<< *x<< endl << endl;
*x = arr [0][3];
cout<< x<< endl;
cout<< *x<< endl;
delete x;
// delete [] arr;
return 0;
}