我刚看了这
在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);
}
产出如下:
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'
现在我糊涂了。C99是否确实支持引用传递?
发布于 2011-03-19 02:43:07
那一页是错的。在C中没有“引用”(甚至在C99中)。
在C中,当您想传递“按引用”时,可以使用指针伪造引用语义。
https://stackoverflow.com/questions/5359677
复制相似问题