int&和a和int& a? [英] Is there a difference between int& a and int &a?
本文介绍了int&和a和int& a?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码:
int a = 5;
int& b = a;
b = 7;
cout << a;
打印出7,并替换 int&带有
也会打印出7。 int& b
的b
prints out 7, and replacing int& b
with int &b
also prints out 7.
实际上 int& b
和 int& b
。
我也用一个简单的类测试了这种行为。通常,是否将&号放置在相对于类型和标识符的位置上是否重要?谢谢。
I tested this kind of behavior with a simple class as well. In general, does it ever matter whether the ampersand is placed relative to the type and identifier? Thanks.
推荐答案
不,除了编码样式外,没有其他区别。我认为有关编码样式的主要论据是以下声明:
No, there is absolutely no difference except coding style. I think the main argument about coding style is that this declaration:
int& a, b;
将 a
声明为 int&
和 b
作为 int
。
这篇关于int&和a和int& a?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文