views:

66

answers:

1

Possible Duplicate:
What’s your preferred pointer declaration style, and why?

Should it be:

center: int * number;
left: int* number;
right: int *number; 

I see the left one as type centric the right one as variable name centric, and the center one as agnostic, but I'm really not sure. Does one make sense in certain situations and not others? I'd like to do it the right way even though I've heard its subjective. (what do most people do?)

When dereferencing, *variable makes the most sense as you are preforming an action on the variable but declaration is not as clear.

+4  A: 

To most people it's a matter of choice. However, do note that the following can be confused by a novice to C:

int* myPointer,
     myInt;

as both being pointers. Thus it is my opinion that if you are going to allow that type of declaration within your code place it as follows:

int  *myPointer,
     myInt;

so that it's not as confusing. In the second, it's more obvious that the * belongs with the myPointer and not the myInt. (Ideally, you'll leave each variable to have it's own full declaration.)

wheaties