Note: This question is about the position of the asterisk (*
).
In most C code I see (e.g., in Beej\'s guide to network programming), all variable declar
Just to throw some controversy into the matter:
int* a; int* b;
int *a;
int* a, * b, * c;
int* (* func)()
.There are other elements of C that are incorrectly used, such as const
, which belongs on the right too! int const a;
. This is commonly put on the left of the type, despite belonging to the type to its left. Many compilers have to be modified to handle this usage. In C++ you can observe this is conformed to with constant methods, as the compiler can't deduce for you if it's put on the left: int A::a() const
. This also breaks down with nested usage of const
, restricted
and friends with such declarations as int const *
. Conventional usage of const
would suggest this is a constant pointer to an integer, but that's actually int *const
.
You've all been doing it wrong all along, put everything on the right.