这段程序会输出什么? #include <iostream>
int main () {
int first = 10 ;
int second = 20 ;
int& current = first;
current = second;
second = 30 ;
std :: cout << first << ' ' << current << ' ' << second << '\n' ;
}
20 20 30 10 30 30 10 20 30 赋值让current改绑,因此行为未定义。 检查
上一道练习 下面哪个声明的形参是转发引用? 测验 下一道练习 审查一段生成的注册表 审查AI代码
问问你的AI 让你的AI把这段代码改成引导式找错练习。
Claude ChatGPT 复制提示词 I am reading "这段程序会输出什么?" on CodeWiki (https://codewiki.com/zh/practice/predict/cpp/references/predict-reference-assignment/).
Context (verbatim from the page):
"""
#include <iostream>
int main() {
int first = 10;
int second = 20;
int& current = first;
current = second;
second = 30;
std::cout << first << ' ' << current << ' ' << second << '\n';
}
"""
Introduce three subtle bugs into the example above and let me find them. Reveal each answer only after I have guessed.
Answer in 中文. Keep code examples in cpp. Where you are unsure, say so.