node * node1与node * node1有什么区别? [英] What is the difference node *node1 vs node* node1?

查看:181
本文介绍了node * node1与node * node1有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1个节点:

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

node  *node1

vs

node*  node1

?

推荐答案

没有typedef,这两个声明都是非法的.

Without a typedef, both the declarations are illegal.

带有typedef之类的

 typedef struct node node;

就位,没有区别.这两个语句都声明了一个指向node的类型的变量node1. (注意:不过,您仍然需要终止的; ).

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;

其中,p是指针类型,但q不是指针类型.

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

像这样写

 node* p, q;

可能产生一种幻觉,即pq都是指针类型,本质上它们是不是.

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

这篇关于node * node1与node * node1有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆