Hello everyone,
We always write const int other than int const, are they the same?
Example,
Code:int const & x = 10;
const int& y = 10;
thanks in advance,
George
Printable View
Hello everyone,
We always write const int other than int const, are they the same?
Example,
Code:int const & x = 10;
const int& y = 10;
thanks in advance,
George
Yes.
Read Stroustrup's answer to: Should I put "const" before or after the type?
I'd logically have to agree, given that Bjarne opens that section with "I put it before, but that's a matter of taste." and then goes on to explain why he prefers it.
The basic rule of thumb with const (like volatile) is that it applies to the thing immediately on its left, unless it is on the left in which case it applies to the thing immediately on its right. According to that, your two examples are exactly equivalent.