initialize a multidimensional C array of variable size to zero
问题 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}; but it is not working if I do this: int i = 10; int j = 10; int myarray[i][j] = {0}; Is there a one-line way of doing this or do I have to loop over each member of the array? Thanks 回答1: You cannot initialize it with an initializer, but you can memset() the array to 0. #include <string.h> int main(void) { int a = 13, b = 42; int m[a][b]; memset(m, 0,