请问c具有参考?

编程入门 行业动态 更新时间:2024-10-28 05:17:51
本文介绍了请问c具有参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

请问c具有参考?即在C ++:

无效美孚(INT&安培; I)

解决方案

没有,没有。它的指针的,但他们不完全是一回事。

在特定的,在C所有的参数都是按值传递,而不是传递按引用是可作为C ++。当然,你可以排序模拟的传递由引用通过指针:

无效美孚(INT * X){    * X = 10;}...INT Y = 0;富(安培; Y); //通过值传递的指针// y值现在是10

有关指针和引用之间差异的更多详细信息,请参阅this SO质疑。 (也请不要问我,因为我不是一个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具有参考?

本文发布于:2023-11-13 14:05:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!