输出C语言中 变量的类型
使用gcc的警告信息间接知道变量的类型
#include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <string.h> int main() { int a[2][10]; printf("%d\n", a[0]); printf("%d\n", a); printf("%d\n", a + 1); exit(0); }
[root@localhost transform]# gcc -o test -Wall -g test.c test.c: In function ‘main’: test.c:14: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int *’ test.c:15: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int (*)[10]’ test.c:16: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int (*)[10]’
gcc 的选项中加入 -Wall 即可
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步