I want to initialize a two-dimensional array of variable size to zero. I know it can be done for a fixed-sized array:
int myarray[10][10] = {0};
You cannot initialize it with an initializer, but you can memset() the array to 0.
memset()
#include int main(void) { int a = 13, b = 42; int m[a][b]; memset(m, 0, sizeof m); return 0; }
Note: this is C99. In C89 the declaration of m ( int m[a][b]; ) is an error.
C99
C89
int m[a][b];