出一道C++基础代码挖空选择题
时间: 2023-08-30 14:04:09 浏览: 39
好的,这是一道C++基础代码挖空选择题:
```cpp
#include <iostream>
using namespace std;
int main() {
int a = 10;
int* p1 = &a;
int* p2 = new int;
____; // 在这里填写代码,使得p2指向a的地址
*p2 = 20; // 修改p2指向的值
cout << "a = " << a << endl;
delete p2;
return 0;
}
```
以下选项中,哪一个可以替换代码的空白处,使得程序输出`a = 20`?
A. `p2 = &a;`
B. `p2 = a;`
C. `p2 = *a;`
D. `p2 = &&a;`
请回答正确选项是什么。
相关问题
出一道C++基础代码挖空题
好的,这是一道C++基础代码挖空题:
```cpp
#include <iostream>
using namespace std;
int main() {
int a = 10;
int& r = ____; // 在这里填写代码,使得r成为a的引用
r++; // 修改引用r的值
cout << "a = " << a << endl;
return 0;
}
```
请在代码中填写适当的语句,使得变量`r`成为变量`a`的引用,并输出`a`的值。
出一道C++基础代码阅读选择题
好的,这是一道C++代码阅读选择题:
```c++
#include <iostream>
using namespace std;
int main() {
int x = 5;
int y = 2;
if (x > y) {
cout << "x is greater than y" << endl;
}
else if (x < y) {
cout << "x is less than y" << endl;
}
else {
cout << "x is equal to y" << endl;
}
return 0;
}
```
在上面的代码中,以下哪个语句会被输出?
A. x is greater than y
B. x is less than y
C. x is equal to y
D. 以上都不是
请回答正确的选项。