What makes more sense – char* string or char *string? [duplicate]

In the following declaration:

char* string1, string2;

string1 is a character pointer, but string2 is a single character only. For this reason, the declaration is usually formatted like:

char *string1, string2;

which makes it slightly clearer that the * applies to string1 but not string2. Good practice is to avoid declaring multiple variables in one declaration, especially if some of them are pointers.

Leave a Comment

tech