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
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.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Read Stroustrup's answer to: Should I put "const" before or after the type?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
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.