TL;DR - that is how C syntax is designed to work.
The *
is considered attached to the variable, because, it defines the type of the variable, not the datatype. The type of an object is supposed to be a property of the object itself, so it makes sense to consider the identifier of the property is associated with the object(variable).
To clarify, by saying int * p;
, we mean to say, p
is a variable of type pointer which points to an int
. So, it makes sense to attach the *
to the variable, rather than to the datatype.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…