White space matters only to the degree that it keeps tokens from running together and (for example) creating a single token, so (for example) int x
is obviously different from intx
.
When you're dealing with something like: int const*x;
, whitespace on either size of the *
makes absolutely no difference to the compiler at all.
The difference between a pointer to const int
and const pointer to int
depends on which side of the *
the const is on.
int const *x; // pointer to const int
int *const x; // const pointer to int
The primary difference is readability when/if you define/declare multiple objects in the same declaration.
int* x, y;
int *x, y;
In the first, somebody might think that x and y are pointers to int -- but in fact, x is a pointer to an int, and y is an int. To some people's eyes, the second reflects that fact more accurately.
One way to prevent any misinterpretation is to only ever define one object at a time:
int *x;
int y;
For any of these, correct interpretation is fairly easy if you ignore whitespace entirely (except to tell you where one toke ends and another starts, so you know "const int" is two tokens) and read from right to left, reading *
as "pointer to". For example: int volatile * const x;
is read as "x is a const pointer to a volatile int".