Just as a follow up to my last post, here’s a quick overview of the const
keyword
1. const int x = 5; 2. const int * px; 3. int const * px; 4. const int * const px;
- A constant integer with a value of 5. The value of x will be 5 for its entire life.
- A pointer to a constant integer. The value of the integer pointed to by px can not be changed; however you may point px to a different integer.
- This is the same as #2. The
const
keyword may appear before or after the type it is qualified on. I prefer the style in #2, but both are syntactically correct. - A constant pointer to a constant integer. You can not change the value of the integer being pointed to, nor can you point px to a different integer.