Создатели языка задумывали синтаксис char *a
(именно с таким расположением звездочки) как некоторую мнемонику: что выражение *a
имеет тип char
:
For each object of such a composed type, there was already a way to mention the underlying object: index the array, call the function, use the indirection operator on the pointer. Analogical reasoning led to a declaration syntax for names mirroring that of the expression syntax in which the names typically appear. Thus,
int i, *pi, **ppi;
declare an integer, a pointer to an integer, a pointer to a pointer to an integer. The syntax of these declarations reflects the observation that i
, *pi
, and **ppi
all yield an int
type when used in an expression.
Dennis Ritchie — The Development of the C Language
Еще больше эта задумка проявляется при объявлении нескольких переменных:
int* foo, bar, ** baz;
В данном случае foo
— это указатель на int
, bar
— просто int
, baz
— указатель на указатель на int
. При использовании другого стиля это было бы более понятно:
int *foo, bar, **baz;
Так что более предпочтительно было бы использовать стиль, где звездочка находится рядом с именем переменной. Если, конечно, это не противоречит style guide на вашем проекте.
char * a
?:) разница в предпочтениях и суевериях.