C – initialization of pointers, asterisk position [duplicate]

It does not matter as far as you are declaring only one pointer. It is usually writen like in the second example (in the code I usually read/write) but for the compiler it’s the same.

The trouble can come out if you are declaring more than one pointer. For example, this is not declaring two pointer, instead it declares one pointer and one var of type type.

type* var1, var2;

You need to do instead:

type* var1, *var2;

I prefer to use the * by the var always.

Leave a Comment