本文介绍了void function(int& a){}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在C ++中看到了这段代码但是在尝试使用C时会导致错误: ------------- void function( int& a){a = 5; } ------------- 这个,传入功能 a指针而不是a价值,但是内部的b b和功能我可以访问a值不是* a但是用a。 为什么这不适用于C?I saw this code in C++ but when tried to C causes an error:-------------void function(int &a) { a = 5; }-------------with this, passed in "function" the "a" pointer instead of "a" value, BUTinside "function" I have access to "a" value not with "*a" but with "a".Why this is not working in C?推荐答案 您试图通过引用传递,这是特定于C ++的。如果你不想复制''a''(你很难担心这个问题)你可以试试两件 的东西。 : void function(int * a){* a = 5; } 或者只是删除&符号 我不会在这里引用,因为这个新闻组是针对C标准的, 不是C ++You are trying to pass by reference, which is C++ specific. You can try twothings, if you don''t want to make a copy of ''a'' (which an int is hardlyanything to worry about):void function(int *a) { *a = 5; }or just remove the ampersand altogetherI won''t get into references here as this newsgroup is for the C standard,not C++ 因为C ++与C不是同一种语言因此,没有明显的原因可以解释为什么C ++功能可以在C中运行。 如果你想使用C,那么学习C. - Chris" electric hedgehog" Dollin C常见问题解答: http://www.faqs.org/faqs/by-newsgrou...mp.lang.c.html C欢迎: http://www.angelfire.com/ms3/bchambl...me_to_clc.html 为什么Fortran语法在C中不起作用? 为什么Pascal语法在C中不起作用? 为什么Perl语法在C中不起作用? 依此类推,等等... 下次,在发布问题之前尝试吸引你的大脑。它没有b $ b(或者,至少,不应该)伤害。 Dan - Dan Pop DESY Zeuthen,RZ集团 电子邮件: Da ***** @ ifh.de 这篇关于void function(int& a){}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-01 18:33