|
发表于 2023-3-28 15:51:10
|
显示全部楼层
本楼为最佳答案
你好!根据你提供的代码,似乎缺少头文件 stdbool.h,因此编译器无法识别 _Bool 关键字。如果你使用的是 C99 或更高版本,那么 _Bool 是 C99 新增的布尔类型,需要包含 stdbool.h 头文件才能使用。
你可以尝试添加以下代码到你的程序的开头:
这样编译器就能够正确地识别 _Bool 关键字了。
此外,由于 sizeof 返回的是 size_t 类型,而不是 int 类型,因此你应该使用 %zu 格式说明符来打印其返回值。因此你的代码应该改成:
- #include <stdio.h>
- #include <stdbool.h>
- int main(void)
- {
- printf("int = %zu\n", sizeof(int));
- printf("short int = %zu\n", sizeof(short));
- printf("long int = %zu\n", sizeof(long));
- printf("long long int = %zu\n", sizeof(long long));
- printf("char = %zu\n", sizeof(char));
- printf("_Bool = %zu\n", sizeof(_Bool));
- printf("float = %zu\n", sizeof(float));
- printf("double = %zu\n", sizeof(double));
- printf("long double = %zu\n", sizeof(long double));
- return 0;
- }
复制代码
希望对你有帮助! |
|