ant*_*a40 4 c99 pass-by-reference
我刚才读这个:
在C ++(和C99)中,我们可以按引用传递,它提供与指针传递相同的性能。
因此,我尝试了以下简单代码:
#include <stdio.h>
void blabla(int& x){
x = 5;
}
int main(){
int y = 3;
printf("y = %d\n", y);
blabla(y);
printf("y = %d\n", y);
}
Run Code Online (Sandbox Code Playgroud)
输出为:
gcc test.c -o test -std=c99
test.c:3:16: error: expected ';', ',' or ')' before '&' token
test.c: In function 'main':
test.c:10:2: warning: implicit declaration of function 'blabla'
Run Code Online (Sandbox Code Playgroud)
现在我很困惑。C99确实支持引用传递吗?
该页面是错误的。C中没有“引用”(即使在C99中)。
在C语言中,当您要传递“按引用”时,您将使用指针来伪造引用语义。