What is the difference between int* ptr and int *ptr in C? [duplicate]

冷暖自知 提交于 2019-11-28 11:27:51

To the compiler, there is no difference between the two declarations.

To the human reader, the former may imply that the "int*" type applies to all declarations in the same statement. However, the * binds only to the following identifier.

For example, both of the following statements declare only one pointer.

int* ptr, foo, bar;
int *ptr, foo, bar;

This statement declares multiple pointers, which prevents using the "int*" spacing.

int *ptr1, *ptr2, *ptr3;

Spaces in C are mostly insignificant. There are occasional cases where spaces are important, but these are few and far between. The two examples you posted are equivalent.

Like the others said. There is no difference. If you want to understand more complex C type declaration you could find this link userful. Reading C declarations.

It's called whitespace operator overloading, see here: http://www2.research.att.com/~bs/whitespace98.pdf

int *p;

*p 


is no meaning for compiler, (int*) is a type named pointer.

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