Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何将返回语句添加到magicTime?_C++_Nullpointerexception_Pass By Reference_Pass By Value - Fatal编程技术网

C++ 如何将返回语句添加到magicTime?

C++ 如何将返回语句添加到magicTime?,c++,nullpointerexception,pass-by-reference,pass-by-value,C++,Nullpointerexception,Pass By Reference,Pass By Value,我试图找到以下代码的输出。 如何将返回语句添加到magicTime? 应该把它放出来 a:10 b:30 c: a:10 b:30 #include <iostream> using namespace std; int magicTime(int a, int &b, const int &c){ a=c; b=20; } int main(){ int a = 10; int b = 30; int c;

我试图找到以下代码的输出。 如何将返回语句添加到magicTime? 应该把它放出来 a:10 b:30 c: a:10 b:30

#include <iostream>
using namespace std;

int magicTime(int a, int &b, const int &c){
    a=c;
    b=20;
}



int main(){

    int a = 10;
    int b = 30;
    int c;

    cout << "a: " << a << " b   " << b << " c   " << c << endl;

    c=b;
    magicTime(c, b, a);

    cout << "a: " << a << " b   " << b << " c   " << c << endl;


    return 0 ;
}
#包括
使用名称空间std;
内部时间(内部时间a、内部时间b、内部时间c){
a=c;
b=20;
}
int main(){
INTA=10;
int b=30;
INTC;

cout好,那么您想要返回一个int数组

伪码

int[] magicTime(int a, int &b, const int &c){
    a=c;
    b=20;
    return new int [] { a, b, c};
}

通过在函数末尾写入
return;
。它应该返回什么?我希望它返回存储在a、b和c中的值。我严重怀疑OP希望这样做。他说他希望返回所有三个值,对吗?也许我误解了这个问题