Declaring pointers; asterisk on the left or right of the space between the type and name? [duplicate]

It’s a matter of preference, and somewhat of a holy war, just like brace style.

The “C++” style

someType* somePtr;

is emphasizing the type of the pointer variable. It is saying, essentially, “the type of somePtr is pointer-to-someType“.

The “C” style

someType *somePtr;

is emphasizing the type of the pointed-to data. It is saying, essentially, “the type of data pointed to by somePtr is someType“.

They both mean the same thing, but it depends on if a given programmer’s mental model when creating a pointer is “focused”, so to speak, on the pointed-to data or the pointer variable.

Putting it in the middle (as someType * somePtr) is trying to avoid committing to either one.

Leave a Comment