Whats the difference between an init-declarator and declarator in C++? An init-declarator may appear in init-declarator-list. Example:
int x, y, z;
or
int x;
int y;
int z;
where x, y, z may be the init-declarators or should i say declarators?
Here is the grammar:
That is,
init-declarator-listmay contain declaration of more than one variable, andinit-declaratormust contain declaration of exactly one variable.That means, in your case, the first code is
init-declarator-listand second code isinit-declarator(andinit-declarator-listboth, sinceinit-declarator-listmay contain just one declaration).But how does it matter what you call what? In everyday use, this difference is almost ignorable.
However, if you want to know about coding-style, then different people declare variables differently. I’ve seen many good programmers who use both style. I usually write all related variables in the same declaration-list, e.g
If you group them as above, it is easier for one to understand the meaning of each variables just by recognizing the group first. It is also easier to use just one comment for each declaration-list (exactly as I did above!) and you’re done. It also helps maintenance to some extent, probably not that much though.