0

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

In C++ What is the difference between:

int* a;

and

int *a;

Is it same?

Community
  • 1
  • 1
Yasin
  • 287
  • 5
  • 15

3 Answers3

3

They are the same. There is no difference. Also same as

int * a;
Phonon
  • 12,549
  • 13
  • 64
  • 114
3

Yes. Those two constructs are identical. int *a; is more C style, because it is consistent with the "declaration follows use" rule in C. This rule means that you can read *a, and know that it gives you an int.

In C++, types get used on their own more often, so int* a; is more typical, as it puts the emphasis on they type being int*. Conformance to "declaration follows use" is less important in C++, because does not work everywhere anyway (it doesn't work with references, for example).

Note that if you write int* a, b; (which is the same as int *a, b;), then only a is a pointer.

Mankarse
  • 39,818
  • 11
  • 97
  • 141
2

Those are the same. You can put the asterisk (*) anyplace.

Jay Slupesky
  • 1,893
  • 13
  • 14