我目前停留在这个问题,但不知道简单的C++函数的困惑是什么,我做错了:关于
完成的功能ADD10()来使程序 可以添加10到每个用户输入整数。 (注意:您应该只改变功能ADD10()的代码,但不要改变其他代码。)
提供给我的原始代码是这样的:
#include <iostream>
#include <iomanip>
using namespace std;
//TODO: complete this function, do NOT change other code
void add10()
{
}
//Please do NOT change the following code
void main()
{
int n;
cin >> n;
add10(n);
cout << n;
}
我已编辑上面的代码,如图下面,但它仍返回相同的值用户输入:
#include <iostream>
#include <iomanip>
using namespace std;
//TODO: complete this function, do NOT change other code
int add10(int n)
{
return n += 10;
}
//Please do NOT change the following code
void main()
{
int n;
cin >> n;
add10(n);
cout << n;
}
是否有人可以帮我解释一下如何解决我的代码和我在做什么错?谢谢!
好吧,我想我明白你的意思。在价值传递和引用传递的概念之间,我不太清楚。如果不是太麻烦,你能简单地解释两者之间的区别吗? –
@RajHeera我可以,但这是另一个单独的问题,已经回答了很多次,所以我只是添加一个链接到我的答案 – Ap31
完美,感谢您的宝贵帮助。将更多地理解这些基本概念。 –