Martin Kristiansen Martin Kristiansen - 8 months ago 82
C Question

Where to put the star in C and C++ pointer notation

Possible Duplicate:

Correct way of declaring pointer variables in C/C++

For some time the following has been annoying me, where should I put the star in my pointer notation.

int *var; // 1


int* var; // 2

obviously do the same thing, and both notations are correct, but I find that most literature and code I look at use the 1th notation.

wouldn't it be more 'correct' to use the 2th notation, separating the type and the variable name by a whitespace, rather than mixing the type and variable tokens?


No. Never. <g>

But consider:

int* var1, var2;

Here, the placement of the * is misleading, because it does not apply to var2, which is an int and not an int*.