注册 登录
编程论坛 C语言论坛

向各位大佬求解!!

coder吴 发布于 2020-12-10 13:25, 1932 次点击
#include <stdio.h>
void main (){
    printf("%d\n ",sizeof(int));
   
}
 报错显示的是 : In function ‘main’:
3:12: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
     printf("%d\n ",sizeof(int));
请问这是什么原因造成的错误啊
3 回复
#2
星泪成寒2020-12-10 13:27
sizeof关键字返回的类型是 long unsigned int, %d 是用来打印int类型, long unsigned int 应该用 %lu 打印
#3
rjsp2020-12-10 16:05
sizeof 的类型是 size_t,在printf/scanf中用 %zu
而 size_t 是不是 long unsigned int,那是实现定义,不一定的。
#4
coder吴2020-12-11 11:13
1