Option 3 is exactly the same as option 1. const applies to everything that belongs to the left . If there is nothing (the first option), this refers to what is on the right . In addition, you are missing one option.
const int* pi1; // varyable pointer to constant int int const* pi2; // again - varyable pointer to constant int int* const pi3; // constant pointer to varyable int // you're missign the next int const * const pi4; // constant pointer to constant int
I personally prefer the second version to the first, as this is what the compiler parses, and when you read the type from right to left, itβs clearer. :) Besides what I did in the comments, itβs intuitive, isn't it?
Oh, yes, all of the above also applies to volatile . Together they are considered cv-qualifiers ( cv = const volatile ).
And as a last point, for future references: Always cdecl.org . As long as you don't mix with C ++ types, you can find out the value of potentially any declaration. Change Interestingly, he chokes on int const i; . I think I will need to investigate whether the variable ordering of cv qualifiers in C ++ has been introduced.
source share