有容乃大

有容乃大

http://www.nowcoder.com/questionTerminal/4712159bbc15417086d40d6c6ff94fee

分析:

对于不同的系统和机器其对应类型的大小有所不同,sizeof运算符可以计算出当前类型的大小,故能够轻松解出本题。

题解:

#include <bits/stdc++.h>
using namespace std;

int main() {
    //使用sizeof运算符输出各种类型的大小
    printf("The size of short is %d bytes.\n", sizeof(short));
    printf("The size of int is %d bytes.\n", sizeof(int));
    printf("The size of long is %d bytes.\n", sizeof(long));
    printf("The size of long long is %d bytes.\n", sizeof(long long));
}

总结:

sizeof运算符的使用,确保代码能够鲁棒的在不同机器上运行。

全部评论

相关推荐

01-08 12:01
门头沟学院 Java
冰炸橙汁_不做oj版:不接好运
点赞 评论 收藏
分享
01-30 09:45
燕山大学 Java
喵_coding:这种直接跑就完事了 哪有毕业了才签合同 任何offer和三方都没有的
点赞 评论 收藏
分享
评论
9
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务