Doesn't matter. (Eg. they are the same.) You could even write char*ptr;
without any whitespace.
Beware though with multiple declarations on one line: char* ptr, noptr;
. Here, the third syntax comes in clearer: char *ptr, noptr;
.
My rule to avoid that confusion: Only one variable per line. Another way to do it right without the possibility to miss a *
: typedef
the pointer, eg:
typedef char* CharPtr;
CharPtr ptr1, ptr2; // now both are pointer
Though then you need to be aware of other things, like const
ness, so I stick to my rule mentioned above:
typedef char* CharPtr;
const CharPtr p1; // const char* ?? or char* const ??
CharPtr const p2; // char* const ?? or const char* ??
// Eg.: Can't the pointer or the pointee be changed?
(And all of the above also applies to references &
.)