Pointer Variable Declaration in C/C
In C and C , there are multiple notations for declaring pointer variables, including:
The question arises: which notation is more appropriate?
According to Bjarne Stroustrup, the creator of C , the choice between the two notations is a matter of style and emphasis.
Notation (a) emphasizes the syntax of the pointer declaration, focusing on the fact that the asterisk () binds to the variable name. In this view, the declaration reads as "p is what is the int."
Notation (b) emphasizes the type of the pointer variable. It reads as "p is a pointer to an int," highlighting the int* type. This emphasis aligns with the strong emphasis on types in C .
Stroustrup recommends using notation (b) for clarity, especially when declaring multiple pointers in a single line. This notation aligns with the common practice of placing the asterisk next to the variable name to indicate pointer status.
The above is the detailed content of Which C/C Pointer Declaration Notation is Better: `char* p` or `char *p`?. For more information, please follow other related articles on the PHP Chinese website!