- 1
Pointer * placement
what the difference between int* a and int *a?
7 Respuestas
+ 5
Right Dennis !
That's an old c style bad declaration convention.
declaring in separate lines however..
int a;
int *b;
float f = 1.5;
char c = '#x27;;
char *d =&c;
+ 5
Danstan Ongubo after seeing your reply I tested it and you were correct. We need to put * with each variable to make it pointer
+ 3
@nAutAxH AhmAd
What do you mean int* a, b, c, d; all of them are integer pointers?
Only a is a pointer, the rest are regular integers.
int* a, int*a, int *a, they mean the same thing, however the last one is prefered just for that same mistake.
+ 2
int *a, b, *c, d;
//In this type of declaration variable a and c are integer pointers and b and d are just normal variables.
int* a, b, c, d;
//In this type of declaration all variables are integer pointers.
+ 2
AZTECCO Good thing I usually declare one variable per line 😅
I actually tested it in playground and wanted to edit the post, but couldn't find the thread anymore ,🙉🙈
+ 1
I prefer to glue it to the data type.
In situation like nAutAxH AhmAd mentioned, I use two lines.
int b, d;
int* a, c;
edit: does not work as explained, so don't use it^^ c won't be a pointer
Or even more often single lines and after semicolon comments about what variable it is and why I need it.
In my opinion this more readable.
However I read quite often, that actually the other way, i.e. int *a, is suggested.
So in the end it is up to you, just be aware of the consequences.