Possible Duplicate:
In C, what is the correct syntax for declaring pointers?
Correct C pointer notation
What is the difference between
int* x
and
int *x
(if one exists) ?
Possible Duplicate:
In C, what is the correct syntax for declaring pointers?
Correct C pointer notation
What is the difference between
int* x
and
int *x
(if one exists) ?
They both the same. Only difference is that you cant declare many variables in such way:
int* x, a, b; //a and b are not pointers
int *x, *a, *b; //all are pointers
I use first notation, for me it shows that variable has pointer type, not pointer itself.
There is no difference. You will get in both cases an int pointer.
A reason to prefer the second one is when you declare multiple variables at once:
int *str, *foo;
int* str, foo;
Those two lines are different, the first one declares two pointers to int, whereas the second one declares one pointer to int and one int type variable.
Whitespace has no significance to the compiler in this case. But, some people might interpret it as meaning differently (as in what points to what). Not a good thing to do in my opinion (since whitespace is not something that should be taken into great account).
there is no difference at all.
In both case these are pointers to int
*
is associated with identifiers not the type
just for clear vision best practice to give space between type
and *
.
int *p;
for e.g. if you write
int *p,q;
means p
is a pointer
but q
is int
. it signifies that * is associated with identifier name
They are the same, but you just have to be careful when declaring multiple variables:
int* x, y; // x is a int*, while y is just an int
int *z, *w; // both z and w are int*