C语言错误集合

    1 #include <stdio.h>
    2
    3 int main()
    4 {
    5     int i = 5;
✹   6     printf("%d %d\n",i);   / * wrong */
    7     return 0;
    8 }
View Code
trp@DESKTOP-ET7Q9JO:~$ gcc -o t1 t1.c
t1.c: In function ‘main’:
t1.c:6:17: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
    6 |     printf("%d %d\n",i);
      |                ~^
      |                 |
      |                 int
View Code

 

    1 #include <stdio.h>
    2
    3 int main()
    4 {
    5     int i = 5, j = 6;
✹   6     printf("%d\n",i, j);
    7     return 0;
    8 }
View Code
trp@DESKTOP-ET7Q9JO:~$ gcc -o t2 t2.c
t2.c: In function ‘main’:
t2.c:6:12: warning: too many arguments for format [-Wformat-extra-args]
    6 |     printf("%d\n",i, j);
View Code

 

    1 #include <stdio.h>
    2
    3 int main()
    4 {
    5     int i = 5;
    6     float x = 6.0;
✹   7     printf("%f %d\n",i, x);
    8     return 0;
    9 }
View Code
trp@DESKTOP-ET7Q9JO:~$ gcc -o t3 t3.c
t3.c: In function ‘main’:
t3.c:7:14: warning: format ‘%f’ expects argument of type ‘double’, but argument 2 has type ‘int’ [-Wformat=]
    7 |     printf("%f %d\n",i, x);
      |             ~^       ~
      |              |       |
      |              double  int
      |             %d
t3.c:7:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘double’ [-Wformat=]
    7 |     printf("%f %d\n",i, x);
      |                ~^       ~
      |                 |       |
      |                 int     double
      |                %f
View Code

 

posted on 2021-11-16 18:25  trp  阅读(43)  评论(0编辑  收藏  举报

导航