随笔- 509  文章- 0  评论- 151  阅读- 22万 

2014-05-08 21:33

题目链接

原题:

largest number that an int variable can fit given a memory of certain size

题目:给定特定内存大小,请问int型的变量能表示的最大整数是多少?

解法:这个“Guy”出的题目总是这样表意不清。特定大小的内存是什么意思?他要说的是字长吧?16位int占两字节,32位以后int都占四字节。这样能表示的最大整数就是(1 << sizeof(int) * 8  - 1) - 1。

代码:

复制代码
 1 // http://www.careercup.com/question?id=4847954317803520
 2 // For n bits, signed integer can reach 2 ^ (n - 1) - 1.
 3 // For n bits, unsigned integer can reach 2 ^ n - 1.
 4 // My question is: is this a real Google interview question? Onsite interview?
 5 // This guy named 'guy' has been posting an awful lot of questions on Careercup, which contains some difficult, tricky, trivial and stupid ones.
 6 // I doubt if he's simply trying to gather more reputation, by means of spam questions. If he's not telling the truth, he's polluting Careercup and misleading other visitors here.
 7 // He should be warned and punished.
 8 int main()
 9 {
10     return 0;
11 }
复制代码

 

 posted on   zhuli19901106  阅读(199)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示