Home >Backend Development >C++ >Where Should the Asterisk Go When Declaring Pointers in C/C ?
Pointer Declaration in C/C : Placement of Asterisk
In C/C , there are two distinct notations for declaring pointer variables:
The placement of the asterisk (*) in these notations has been a subject of debate among programmers.
Rational Behind Notation (a)
Notation (a) is sometimes used because it follows the grammar rules of C/C . In the declaration char* p;, the asterisk is associated with the variable name p. This implies that *p is of type char.
Case for Notation (b)
However, many programmers prefer Notation (b) for several reasons:
Conclusion
Ultimately, the choice between Notation (a) and Notation (b) is a matter of style and preference. However, C 's emphasis on types makes Notation (b) a more logical and intuitive approach.
The above is the detailed content of Where Should the Asterisk Go When Declaring Pointers in C/C ?. For more information, please follow other related articles on the PHP Chinese website!