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

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.

Leave a Comment