[英]Does C have references?
Does C have references? C有引用吗? ie as in C++ : 即在C ++中:
void foo(int &i)
No, it doesn't. 不,它没有。 It has pointers , but they're not quite the same thing. 它有指针 ,但它们并不完全相同。
In particular, all arguments in C are passed by value, rather than pass-by-reference being available as in C++. 特别是,C中的所有参数都是通过值传递的,而不是像C ++中那样可以通过引用传递。 Of course, you can sort of simulate pass-by-reference via pointers: 当然,您可以通过指针模拟传递引用:
void foo(int *x)
{
*x = 10;
}
...
int y = 0;
foo(&y); // Pass the pointer by value
// The value of y is now 10
For more details about the differences between pointers and references, see this SO question . 有关指针和引用之间差异的更多详细信息,请参阅此SO问题 。 (And please don't ask me, as I'm not a C or C++ programmer :) (请不要问我,因为我不是C或C ++程序员:)
Conceptually, C has references, since pointers reference other objects. 从概念上讲,C有引用,因为指针引用其他对象。
Syntactically, C does not have references as C++ does. 从语法上讲,C没有C ++那样的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.