0

There are two ways to "look at" variable int * a:

  • You can consider a as a variable of type int*.
  • You can consider *a as a variable of type int.

Hence, some people would declare int* a, whereas others would declare int *a.


I would like to know with regards to the two approaches above:

  • What are the arguments in favor and against each one of them?
  • Which one of them is generally consider a better coding convention?

The standard appears to be "discouraging" the use of the int* a approach:

  • It cannot be applied when declaring a function pointer int (*func)(int x).
  • It cannot be applied when declaring several pointers in the same line int *a,*b,*c.

I've been using the int* a approach most of my professional life.

But it turns out to be in contrast with what most people do.

Any additional insights will be highly appreciated.

barak manos
  • 29,648
  • 10
  • 62
  • 114
  • I've been using `int* a` for years, that is what my company's coding standard says too. Just for some anecdotal reinforcement. – Cory Kramer Aug 30 '14 at 21:08
  • Regardless of whitespace, the declaration will be parsed as `int (*a)`; the `*` is bound to the declarator, not the type specifier. – John Bode Aug 30 '14 at 22:20

0 Answers0