c语言第6P的代码,我没有抄错,为什么还报错啊
{:5_104:}#include <stdio.h>
int main()
{
int i;
char j;
float k;
i = 123;
j = 'c';
k = 3.14;
printf("size of int is %d\n", sizeof(int));
printf("size of i is %d\n", sizeof(i));
printf("size of char is %d\n", sizeof(char));
printf("size of j is %d\n", sizeof j);
printf("size of float is %d\n", sizeof(float));
printf("size of k is %d\n", sizeof k);
return 0;
}
分割
test.c:13:35: warning: format specifies type 'int' but the argument has type
'unsigned long' [-Wformat]
printf("size of int is %d\n", sizeof(int));
~~ ^~~~~~~~~~~
%lu
test.c:14:33: warning: format specifies type 'int' but the argument has type
'unsigned long' [-Wformat]
printf("size of i is %d\n", sizeof(i));
~~ ^~~~~~~~~
%lu
test.c:15:36: warning: format specifies type 'int' but the argument has type
'unsigned long' [-Wformat]
printf("size of char is %d\n", sizeof(char));
~~ ^~~~~~~~~~~~
%lu
test.c:16:33: warning: format specifies type 'int' but the argument has type
'unsigned long' [-Wformat]
printf("size of j is %d\n", sizeof j);
~~ ^~~~~~~~
%lu
test.c:17:37: warning: format specifies type 'int' but the argument has type
'unsigned long' [-Wformat]
printf("size of float is %d\n", sizeof(float));
~~ ^~~~~~~~~~~~~
%lu
test.c:18:33: warning: format specifies type 'int' but the argument has type
'unsigned long' [-Wformat]
printf("size of k is %d\n", sizeof k);
~~ ^~~~~~~~
%lu
6 warnings generated.
有没有大神知道{:10_266:} 你的编译器非常古怪,像下面这样修改试试看
printf("size of int is %d\n", (int) sizeof(int)) ;
printf("size of i is %d\n", (int) sizeof(i)) ;
printf("size of char is %d\n", (int) sizeof(char)) ;
printf("size of j is %d\n", (int) sizeof(j)) ;
printf("size of float is %d\n", (int) sizeof(float)) ;
printf("size of k is %d\n", (int) sizeof(k)) ;
不过,都是警告信息,应该不会影响代码的编译和正常运行 代码是对的,没有问题,可能是你用的编译器版本原因,我用Dev C++和vim都试过了,没问题 printf("size of i is %d\n", sizeof i); 是的,可能是我的编译器问题,我用的是mac终端
页:
[1]