Careercup - Google面试题 - 4847954317803520

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。

代码:

 // http://www.careercup.com/question?id=4847954317803520
// For n bits, signed integer can reach 2 ^ (n - 1) - 1.
// For n bits, unsigned integer can reach 2 ^ n - 1.
// My question is: is this a real Google interview question? Onsite interview?
// This guy named 'guy' has been posting an awful lot of questions on Careercup, which contains some difficult, tricky, trivial and stupid ones.
// 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.
// He should be warned and punished.
int main()
{
return ;
}
上一篇:jQuery 常用知识点总结


下一篇:Windows terminal 启动 WSL GIT-BASH CMD Powershell 我的配置json