- 1

Pointer * placement

what the difference between int* a and int *a?

25th Sep 2018, 11:30 AM
Ader
Ader - avatar
7 Antworten
+ 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;
25th Sep 2018, 3:02 PM
AZTECCO
AZTECCO - avatar
+ 5
Matthias be careful! c won't be a pointer as Dennis explained.
25th Sep 2018, 3:04 PM
AZTECCO
AZTECCO - avatar
+ 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
26th Sep 2018, 5:00 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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.
25th Sep 2018, 2:03 PM
Dennis
Dennis - avatar
+ 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.
25th Sep 2018, 12:46 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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 ,🙉🙈
26th Sep 2018, 5:35 AM
Matthias
Matthias - avatar
+ 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.
25th Sep 2018, 1:12 PM
Matthias
Matthias - avatar