本文介绍了请问c具有参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请问c具有参考?即在C ++:
无效美孚(INT&安培; I)
解决方案
没有,没有。它的指针的,但他们不完全是一回事。
在特定的,在C所有的参数都是按值传递,而不是传递按引用是可作为C ++。当然,你可以排序模拟的传递由引用通过指针:
无效美孚(INT * X)
{
* X = 10;
}...INT Y = 0;
富(安培; Y); //通过值传递的指针
// y值现在是10
有关指针和引用之间差异的更多详细信息,请参阅。 (也请不要问我,因为我不是一个C或C ++程序员:)
Does C have references? i.e. as in 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++. 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. (And please don't ask me, as I'm not a C or C++ programmer :)
这篇关于请问c具有参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!