0
Where do you guys prefer to put the asterisk (*) in pointer declaration?
int *ptr; int * ptr; int* ptr; which one do you prefere? And why? Could you please give your reasons.
4 ответов
+ 2
to attach variable name, To avoid confusion 😀
+ 2
like this:
int* p, q;
which one is a pointer?
0
I prefer
int* ptr;
because it separates type (here: pointer to int) from name (here: 'ptr') by a white space. You can see directly that the type is a pointer.
(Seeing
int *ptr;
lets me think of as an integer, that is by some magical name convension of the variable name (by preposing asterisk) transformed into a pointer.)
0
@Omar
Confusion about what?
Omar answered:
like this:
int* p, q;
which one is a pointer?
yes, you're right about this. p is a pointer, q is not. that's sneaky.
I usually avoid this by writing:
int* p;
int* q;
:-)