Possible Duplicate:
In C, what is the correct syntax for declaring pointers?
When I read C code, I see several ways to write a pointer,like
int *p;
char * s;
char * d = &c;
ll_model* model = new_ll_model(n, cc->term);
double* avg_ll;
My questions are:
-
Are there any differences between them?
-
If there are, what are the differences? That is, does the position of white space and the
*mean something? -
Which way is the right way to write a pointer, so it is readable to myself and any other person who will read my code
Basically, there’s no difference between them.
But I prefer this method:
Instead of:
or
The reason is that because if you want to declare a number of
int *in the same line, it makes more sense to have the*next to the identifier instead of the type because that looks cleaner and less confusing. e.g.is better than:
If you don’t like my reasons, make sure you stick to one of them and don’t vary the usage.