开发者

Pass by reference in C99

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(){开发者_如何学Python
    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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜