int (*a)[n] 中 a 的类型是什么
  • 板块学术版
  • 楼主H3PO4
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/11/12 11:38
  • 上次更新2023/11/12 13:57:00
查看原帖
int (*a)[n] 中 a 的类型是什么
178437
H3PO4楼主2023/11/12 11:38

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]'

2023/11/12 11:38
加载中...