In C, what is the correct syntax for declaring pointers?

I vaguely recall seeing this before in an answer to another question, but searching has failed to yield the answer.

I can't recall what is the proper way to declare variables that are pointers. Is it:

Type* instance;

Or:

Type *instance;

Although I know both will compile in most cases, I believe there are some examples where it is significant, possibly related to declaring multiple variables of the same type on the same line, and so one makes more sense than the other.


It is simply a matter of how you like to read it.

The reason that some people put it like this:

Type *instance;

Is because it says that only instance is a pointer. Because if you have a list of variables:

int* a, b, c;

Only a is a pointer, so it's easier like so

int *a, b, c, *d;

Where both a and d are pointers. It actually makes no difference, it's just about readability.

Other people like having the * next to the type, because (among other reasons) they consider it a "pointer to an integer" and think the * belongs with the type, not the variable.

Personally, I always do

Type *instance;

But it really is up to you, and your company/school code style guidelines.


Those two are the same. However, if you do multiple declarations, the former can trap you.

int* pi, j;

declares an int pointer (pi) and an int (j).