What is the difference node *node1 vs node* node1? [duplicate]

血红的双手。 提交于 2020-01-15 11:15:10

问题


I have 1 node:

struct node
    {
        int key;
        struct node *left, *right;
    };

What is the difference between

node  *node1

vs

node*  node1

?


回答1:


Without a typedef, both the declarations are illegal.

With a typedef like

 typedef struct node node;

in place, there's no difference. Both the statements declare a variable node1 of type pointer to node. (Note: You'll still be needing the terminating ;, though).

It's a matter of choice, but some (including me) prefer to attach the pointer notation to the variable, to avoid misunderstanding, in case of multiple variable declaration, like

 node *p, q;

where, p is pointer type, but q is not.

Writing it like

 node* p, q;

may create the illusion that p and q both are of pointer type, where, in essence, they are not.



来源:https://stackoverflow.com/questions/44055033/what-is-the-difference-node-node1-vs-node-node1

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