📝 ### 第16题 **阅读程序(一)**(下列程序供第 16~20 题使用;判断题正确填√,错误填×) ```cpp 01 #include <iostream> 02 using namespace std; 03 04 int f(int x) { 05 …
📂 C++
· ⚡ 难度 4
· ❓ 判断题
· 📖 CSP-J考前模拟1
### 第16题
**阅读程序(一)**(下列程序供第 16~20 题使用;判断题正确填√,错误填×)
```cpp
01 #include <iostream>
02 using namespace std;
03
04 int f(int x) {
05 int cnt = 0;
06 while (x) {
07 x &= (x - 1);
08 cnt++;
09 }
10 return cnt;
11 }
12
13 int g(int x) {
14 return x & (-x);
15 }
16
17 int main() {
18 int n;
19 cin >> n;
20 cout << f(n) << " " << g(n) << endl;
21 return 0;
22 }
```
**判断题**:当输入 `n` 为负数(如 `-5`)时,`f(n)` 函数内部会陷入死循环。( )