问题
Is there any differences between these two declarations?
int* a;
int *a;
Or these two declarations are the same (pointer to an integer)?
回答1:
They're exactly the same, but here's a small gotcha I came across when first learning C years ago. The * binds to the variable, not the type. This means that
int* a, b;
Declares a
as a pointer to int, and b
as an int. To declare both as pointers, one should do.
int *a, *b;
This is why I prefer to place the *
next to the name.
来源:https://stackoverflow.com/questions/20306168/differences-between-pointer-declaration