GMa*_*ckG 37
C没有参考.您需要将指针传递给您要修改的变量:
int locate(char *name, int *s, int *i)
{
/* ... */
*s = 123;
*i = 456;
}
int s = 0;
int i = 0;
locate("GMan", &s, &i);
/* s & i have been modified */
Run Code Online (Sandbox Code Playgroud)
Ash*_*ish 20
C没有引用变量,但您可以将引用视为const指向数据的指针,因此,
使const指针指向这样的数据,以便指针不能指向其他数据,但可以更改指向它的数据.
int locate (char *name, int * const s, int * const i)
Run Code Online (Sandbox Code Playgroud)
C不支持通过引用传递.你需要用C++来编写或修改它
int locate(char *name, int *s, int *i)
Run Code Online (Sandbox Code Playgroud)
并传递指向第二个和第三个参数变量的指针.