考虑下面的代码片段,检查一个数字是否是2的幂。
null
/* Incorrect function to check if x is power of 2*/ bool isPowerOfTwo (unsigned int x) { return (!(x&(x-1))); } |
上述功能有什么问题? (A) 它的作用与要求相反 (B) 它适用于所有x值。 (C) 它不适用于x=0 (D) 它不适用于x=1 答复: (C) 说明: 请看 https://www.geeksforgeeks.org/program-to-find-whether-a-no-is-power-of-two/ 这个问题的小测验
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END