int (*a)[n] = malloc(sizeof *a); 在使用 C++ 编译器编译时会报错 error: cannot initialize a variable of type 'int (*)[n]' with an rvalue of type 'void *';
但是改成 int (*a)[n] = (int (*)[n])malloc(sizeof *a); 则会报错 error: cannot initialize a variable of type 'int (*)[n]' with an rvalue of type 'int (*)[n]';
改成 int (*a)[n] = (typeof(a))malloc(sizeof *a); 就能通过编译。
所以 a 的类型是什么?
尝试输出 a 的类型但是失败了:printf("%s\n", typeid(a).name()); 会报错 error: 'typeid' of variably modified type 'int (*)[n]'