psihodelia psihodelia - 28 days ago 6x
C Question

C - initialization of pointers, asterisk position

Possible Duplicate:

Pointer declarations in C++: placement of the asterisk

What is the most proper way to place asterisk? Why?

1) type* var;
2) type *var;


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.