izeof.c:35:39: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long un

在打印输出数据类型的练习中报错

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位系统上试了正常输出

在这里插入图片描述

在这里插入图片描述
关注公众号,获取更多精彩内容

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值