Pointer Declaration: Asterisk Placement Quandary
In the realm of C and C programming, the placement of the asterisk in pointer declarations has sparked a heated debate. The two prevalent methods are juxtaposing the asterisk with either the type name or the variable name.
C Style: Emphasizing Pointer Type
Advocates of this style prioritize the pointer's type. This declaration denotes that somePtr is a pointer of type someType.
C Style: Emphasizing Pointed-to Type
In this approach, the asterisk's adjacency to the variable name highlights the data type pointed to by somePtr.
Preference and Semantics
Ultimately, the choice between these two styles is a matter of personal preference. There is no definitive consensus on which one is superior.
However, some proponents argue that the C style aligns better with the object-oriented paradigm, as it emphasizes the pointer's type. On the other hand, the C style may be more intuitive for programmers accustomed to its notation in C.
Middling Placement: Avoiding Commitment
A third approach, placing the asterisk in the middle (e.g., someType *somePtr), attempts to avoid adhering to either the C or C style. However, this middle ground does not offer any additional semantic benefit.
The above is the detailed content of C or C Pointer Declaration: Where Should the Asterisk Go?. For more information, please follow other related articles on the PHP Chinese website!