如何在magicTime中添加return语句?

时间:2014-10-08 03:35:46

标签: c++ nullpointerexception pass-by-reference pass-by-value

我试图找到以下代码的输出。 如何在magicTime中添加return语句? 输出应该是 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 ;
}

1 个答案:

答案 0 :(得分:-1)

好的,所以你想要返回一个int

数组

伪代码

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