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.

27th Apr 2017, 5:25 PM
needmorechocolate
needmorechocolate - avatar
4 Respuestas
+ 2
to attach variable name, To avoid confusion 😀
27th Apr 2017, 5:35 PM
Omar
Omar - avatar
+ 2
like this: int* p, q; which one is a pointer?
27th Apr 2017, 5:47 PM
Omar
Omar - avatar
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.)
27th Apr 2017, 5:38 PM
needmorechocolate
needmorechocolate - avatar
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; :-)
27th Apr 2017, 5:42 PM
needmorechocolate
needmorechocolate - avatar