我为我的课写了一个练习程序,除了返回变量的值之外,其中的所有内容都有效。我的问题是,为什么它没有返回值?以下是我写出的示例代码,以避免复制和粘贴大部分不相关的代码。返回不返回变量值
#include <iostream>
using std::cout; using std::cin;
using std::endl; using std::fixed;
#include <iomanip>
using std::setw; using std::setprecision;
int testing();
int main()
{
testing();
return 0;
}
int testing() {
int debtArray[] = {4,5,6,7,9,};
int total = 0;
for(int debt = 0; debt < 5; debt++) {
total += debtArray[debt];
}
return total;
}
该代码只是丢弃返回值。尝试将'testing();'更改为'std :: cout << testing();'看看你是否没有得到什么。 –
'testing'函数的确会返回一个值。但是你只是在通话中放弃了这个价值。你期望会发生什么? –
*“以下是我为避免复制和粘贴大部分不相关的代码而写出的示例代码。”* - 我们非常感谢您的支持。 –