This code:
int a = 5;
int& b = a;
b = 7;
cout << a;
prints out 7, and replacing int& b
with int &b
also prints out 7.
In fact so does int&b
and 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;
declares a
as an int&
and b
as an int
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With