我像这样定义一个int:
int a;
Run Code Online (Sandbox Code Playgroud)
当我想查找这个int的大小时,我必须使用格式说明符%ld,如下所示:
printf("int size is %ld\n", sizeof(a));
Run Code Online (Sandbox Code Playgroud)
当我使用%d作为格式说明符时,我收到以下错误:
foo.c:7:10: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("int size is %d\n", sizeof(a));
Run Code Online (Sandbox Code Playgroud)
问题是,当函数的参数为int时,为什么sizeof()的结果定义为long unsigned int?