Home >Backend Development >C++ >Why is `char *string` the preferred syntax for declaring character pointers in C ?
Declaration of Character Pointers: char string vs. char string
When declaring character pointers in C , one might come across two common formatting styles: char string and char string. This question delves into the rationale behind the latter format.
In the declaration char string, the "" is associated with "string," indicating that "string" is a pointer to a char. However, this may not be immediately evident.
Conversely, in the declaration char string, the spacing emphasizes that the "" applies to "char," indicating that "string" is a pointer to a char. This format aims to clarify the relationship between the pointer and the variable it references.
Furthermore, it is generally considered good practice to avoid declaring multiple variables in a single declaration, especially if some of them are pointers. Doing so can lead to confusion and potential errors. Therefore, the preferred format is char *string, with a space separating the pointer asterisk from the variable name.
The above is the detailed content of Why is `char *string` the preferred syntax for declaring character pointers in C ?. For more information, please follow other related articles on the PHP Chinese website!