nullusDefectus wrote:
Also, the declaration
char *c, d
makesc
achar*
, butd
achar
. This confuses beginners who are used to declarations such asint a, b
which makes botha
andb
int
s. Thus, the declarationchar* c
is preferred: easier to learn and safer.
Your claim and conclusion are backwards! It's writing char* c, d;
that confuses beginners for the exact reason that you give. Writing char *c, d;
is the correct way to teach, learn, and remind yourself and readers of your code that the *
applies to c
only. Given the language grammar...
simple-declaration ::= decl-specifier-seq init-declarator-list(optional) ;
Note the space ---^
... writing...
char *c;
---^
... also demonstrates that you know what you're doing. This is how you explain it to beginners and they will remember... ;)