可以使用sizeof
运算符计算出给定类型占用的字节数。以下是如何存储应用sizeof
运算符产生的值:
size_t size = sizeof(long long);
该程序将输出每种数字类型占用的字节数:
#include <stdio.h>
int main(void)
{
printf(Variables of type char occupy %u bytes\n, sizeof(char));
printf(Variables of type short occupy %u bytes\n, sizeof(short));
printf(Variables of type int occupy %u bytes\n, sizeof(int));
printf(Variables of type long occupy %u bytes\n, sizeof(long));
printf(Variables of type long long occupy %u bytes\n, sizeof(long long));
printf(Variables of type float occupy %u bytes\n, sizeof(float));
printf(Variables of type double occupy %u bytes\n, sizeof(double));
printf(Variables of type long double occupy %u bytes\n, sizeof(long double));
return 0;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。