Pointer declaration style in C

Jan. 16th, 2004 | 05:45 pm

When you declare a pointer in C, where do you place the pointer operator, close to the type name or close to the variable name?

#1: Close to Type Name

char* name;

#2: Close to Variable Name

char *name;

Poll #234089
Open to: All, results viewable to: All

In C pointer declarations, where do you place the pointer operator?

View Answers

Close to Type Name
10 (31.2%)

Close to Variable Name
20 (62.5%)

WTF?
2 (6.2%)


I use #1, and when I have multiple declarations in the same statement, it looks like this:

char* name, * address, * phone;

I see the pointer operator as part of the type name, and I apply the rule to function pointer declarations as well:

int* (* func)(void);

That's a pointer to a function that takes no arguments and returns a pointer to an int.

Update: Now I remember where I picked up my rationale. C++ Style and Technical FAQ.

#