const int
means an integer that cannot be changed.int*
a pointer to an integer. So far so good. Now for the tricky part:const int*
int const*
Both are equal and describe a pointer to an integer that cannot be changed. The pointer itself can be changed to pointint* const
Okaaaay So this is a constant pointer to an int. The int can be changed (through the pointer), but the pointer itselfconst int* const
The final version, both the pointer and the value it points to cannot be changed.ansi-C | -> | C2 |
const int | const int | |
const int* | (const int)* | |
int* const | const (int*) | |
const int* const | const (const int*) |
ansi-C | -> | C2 |
const int | const int | |
const int* | (const int)* | |
int* const | type IPtr int*; const IPtr | |
const int* const | type CIPtr const int*; const CIPtr |
Now for the tricky part:Code: [Select]const int*
Both are equal and describe a pointer to an integer that cannot be changed. The pointer itself can be changed to point
int const*
at something else. Syntax here is already becoming more vague.
ansi-C | -> | C2 |
const int | const int | |
int const | const int | |
const int* | const int* | |
int const * | const int* | |
int* const | int* const | |
const int* const | const int* const | |
const int * const | const int* const | |
const int * const * | const int* const * | |
const int * const *const | const int* const * const |
const int a = 4;
int * const b = &c;
The variables a and b are both constant, but in one case the const qualifier is before the type,ansi-C | -> | C2 |
const int | int const | |
int const | int const | |
const int* | int const * | |
int const * | int const * | |
int* const | int * const | |
const int* const | int const * const | |
const int * const | int const * const ((((int) const) *) const) // parentheses to clarify ast structure | |
const int * const * | int const * const * ((((int) const) *) const) *) // parentheses to clarify ast structure | |
const int * const *const | int const * const * const (((((int) const) *) const) *) const) // parentheses to clarify ast structure |
int const * const X = &b;
"X is a constant pointer to a constant int"ansi-C | -> | C2 |
const int | const int | |
int const | const int | |
const int* | const int * | |
int const * | const int * | |
int* const | int const * | |
const int* const | const int const * | |
const int * const | const int const * ((const (int)) (const *)) // parentheses to clarify ast structure :/ | |
const int * const * | const int const * * | |
const int * const * const | const int const * const * |
int volatile x = 10;
Foo const foo = { ... };
int * const y = &x;
// or
volatile int x = 10;
const Foo foo = { ... };
int const* y = &x;
int* volatile x = 10; // volatile pointer to int
Foo* const foo = { ... }; // const pointer to Foo
Foo const* foo = { ... }; // pointer to const Foo
int* const y = &x; // const pointer to int
int const* y = &x; // pointer to const int
int volatile* x = 10; // volatile pointer to int
Foo const* foo = { ... }; // const pointer to Foo
const Foo* foo = { ... }; // pointer to const Foo
int const* y = &x; // const pointer to int
const int* y = &x; // pointer to const int
volatile (int*) x = 10; // volatile pointer to int
const (Foo*) foo = { ... }; // const pointer to Foo
(const Foo)* foo = { ... }; // pointer to const Foo
const (int*) y = &x; // const pointer to int
(const int)* y = &x; // pointer to const int