有容乃大

有容乃大

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运算符的使用,确保代码能够鲁棒的在不同机器上运行。

全部评论

相关推荐

龙珠传说:nb,公务员解约不需要支付违约金吧
点赞 评论 收藏
分享
湫湫湫不会java:先投着吧,大概率找不到实习,没实习的时候再加个项目,然后把个人评价和荣誉奖项删了,赶紧成为八股战神吧,没实习没学历,秋招机会估计不多,把握机会。或者说秋招时间去冲实习,春招冲offer,但是压力会比较大
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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