node * node1与node * node1有什么区别? [英] What is the difference node *node1 vs 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;
可能产生一种幻觉,即p
和q
都是指针类型,本质上它们是不是.
may create the illusion that p
and q
both are of pointer type, where, in essence, they are not.
这篇关于node * node1与node * node1有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!