I am trying to init a static array in a function.
int query(int x, int y) {
static int res[100][100]; // need to
You can do it for example the following way by means of introducing one more static variable
int query(int x, int y) {
static bool initialized;
static int res[100][100]; // need to be initialized to -1
if ( not initialized )
{
for ( auto &row : res )
{
for ( auto &item : row ) item = -1;
}
initialized = true;
}
if (res[x][y] == -1) {
res[x][y] = time_consuming_work(x, y);
}
return res[x][y];
}