C函数,使用指针代替返回

the*_*eva 0 c pointers

我有这个功能:

void update(int something, int nothing) {
    something = something+4;
    nothing = 3;
}
Run Code Online (Sandbox Code Playgroud)

然后是函数调用:

int something = 2;
int nothing = 2;

update(something, nothing);
Run Code Online (Sandbox Code Playgroud)

在函数内部,有些东西是6,没有东西是3,但因为我们不返回任何东西,所以值不会改变.

对于一个值,我可以使用函数的返回值,但现在我认为我必须使用指针,对吧?

我想要从函数返回的东西和什么都没有,所以我可以在函数调用后使用新的值,我该怎么做?:)

Rei*_*erd 8

使用发送值&并使用它们接收它们*

例:

void update(int* something, int* nothing) {
    *something = *something+4;
    *nothing = 3;
}

int something = 2;
int nothing = 2;

update(&something, &nothing);
Run Code Online (Sandbox Code Playgroud)

两年没有使用C,但我认为这是正确的.