Differences between pointer declaration [duplicate]

╄→гoц情女王★ 提交于 2021-02-05 12:29:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!