问题
I just read this:
In C++ (and C99), we can pass by reference, which offers the same performance as a pointer-pass.
So I tried this simple code:
#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);
}
The output was:
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'
Now I'm confused. Is pass by referenced indeed supported by C99?
回答1:
That page is wrong. There are no "references" in C (even in C99).
In C, when you want to pass "by reference," you fake reference semantics using a pointer.
来源:https://stackoverflow.com/questions/5359677/pass-by-reference-in-c99