Possible Duplicates:
Declaring pointers; asterisk on the left or right of the space between the type and name?
what is the difference between const int*, const int * const, int const *
I’ve been wondering what is the difference between:
float const &var
const float &var
And which one of these is the correct way of writing the code? (including the above example):
float const& var
float const &var
float const & var
and with pointers:
float * var
float *var
float* var
I always put the special marks just before the variable name, feels most logical. Is that the correct way ?
All are equally valid. There is no one correct way; you should do whichever you find most readable (for your own code) or follow the prevailing style (if working with others).
Putting
constfirst (e.g.,const float &rather thanfloat const &) is more common in my experience.The positioning of
&and*depends on programmer; no choice seems more common than any other, in my experience.