csppass
连续 00 XP登录 / 注册
202116判断题枚举与模拟普及-

程序(一,popcount与最低位):n=1001是否越界

题目

阅读下面的程序,回答问题。 #include <iostream> using namespace std; int n; int a[1000]; int f(int x) { int ret = 0; for (; x; x &= x - 1) ret++; return ret; } int g(int x) { return x & -x; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cout << f(a[i]) + g(a[i]) << ' '; cout << endl; return 0; } 判断题:输入的 n 等于 1001 时,程序不会发生下标越界。( )

考点拆解
程序阅读与结果判断
易错提醒
阅读程序题要按变量变化顺序手推,不要跳步
选择题要检查单位、边界和题目中的否定词