difference between int* i and int *i
They are the same. The two different styles come from a quirk in C syntax.
Some people prefer int* i;
because int*
is the type of i.
Others prefer int *i;
because the parser attaches the star to the variable, and not the type. This only becomes meaningful when you try to define two variables on the line. Regardless of how you write it:
int* i,j;
int*i,j;
int *i,j;
in each of those, i
is a pointer to an int, while j is just an int. The last syntax makes that clearer, although, even better would be:
int j, *i;
or best yet:
int *i;
int j;
As far as C goes they both do the same thing. It is a matter of preference. int* i
shows clearly that it is an int pointer type. int *i
shows the fact that the asterisk only affects a single variable. So int *i, j
and int* i, j
would both create i
as an int pointer and j
as an int.
int* i
and int *i
are completely equivalent