在打印输出数据类型的练习中报错
izeof.c:35:39: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat=]
35 | printf(“sizeof(l)=%d, sizeof(float)=%d\n”, sizeof(l), sizeof(float));
| ~^ ~~~~~~~~~~~~~
| | |
| int long unsigned int
| %ld
源代码:
/*sizeof演示*/
#include <stdio.h>
int main(void)
{
char a = 1;
unsigned char b = 2;
printf("sizeof(a)=%d, sizeof(char)=%d\n", sizeof(a), sizeof(char));
printf("sizeof(b)=%d, sizeof(unsigned char)=%d\n", sizeof(b), sizeof(unsigned char));
short c = 3;
unsigned short d = 4;
printf("sizeof(c)=%d, sizeof(short)=%d\n", sizeof(c), sizeof(short));
printf("sizeof(d)=%d, sizeof(unsigned short)=%d\n", sizeof(d), sizeof(unsigned short));
int e = 4;
unsigned int f = 5;
printf("sizeof(e)=%d, sizeof(int)=%d\n", sizeof(e), sizeof(int));
printf("sizeof(f)=%d, sizeof(unsigned int)=%d\n", sizeof(f), sizeof(unsigned int));
long g = 6;
unsigned long h = 7;
printf("sizeof(g)=%d, sizeof(long)=%d\n", sizeof(g), sizeof(long));
printf("sizeof(h)=%d, sizeof(unsigned long)=%d\n", sizeof(h), sizeof(unsigned long));
long long i = 8;
unsigned long long j = 9;
printf("sizeof(i)=%d, sizeof(long long)=%d\n", sizeof(i), sizeof(long long));
printf("sizeof(j)=%d, sizeof(unsigned long long)=%d\n", sizeof(j), sizeof(long long));
double k = 10.11;
printf("sizeof(k)=%d, sizeof(double)=%d\n", sizeof(k), sizeof(double));
float l = 9.8;
printf("sizeof(l)=%d, sizeof(float)=%d\n", sizeof(l), sizeof(float));
int s = 250;
sizeof(s = 300);
printf("s = %d\n", s);
return 0;
}
报错截图:
原因:
这是由于系统架构导致的问题,因为C语言是底层语言,在不同的系统架构中,会有一写细节不同,比如在ubuntu中写的C程序,在windows上再编译就过不了
然后我又在ubuntu16的32位系统上试了正常输出
关注公众号,获取更多精彩内容