在功能参数struct关键字,有什么区别? [英] Struct keyword in function parameters, what is the difference?
本文介绍了在功能参数struct关键字,有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道,之间有什么区别:
结构节点
{
int数据;
节点*接下来的;
};
和
结构节点
{
int数据;
结构节点*接下来的;
};
为什么我们需要结构
在第二个例子中的关键字?
另外,是
之间的差 无效美孚(节点*头)
{
节点* CUR =头;
// ....
}
和
无效美孚(结构节点*头)
{
结构节点* CUR =头;
// ....
}
解决方案
只有声明,包括结构
是否有在C ++中没有差异C.有效。
不过,您可以的typedef
的结构
在C,所以你不必把它每次写
typedef结构节点
{
int数据;
结构节点*接下来的; //我们还没有完成的typedef还
} SNode;SNode * CUR =头; // OK在这里提及的类型定义
本语法也是C ++的兼容性有效。
I wonder, what is the difference between:
struct Node
{
int data;
Node *next;
};
and
struct Node
{
int data;
struct Node *next;
};
Why do we need struct
keyword in second example?
Also, what is the difference between
void Foo(Node* head)
{
Node* cur = head;
//....
}
and
void Foo(struct Node* head)
{
struct Node* cur = head;
//....
}
解决方案
Only the declarations including struct
are valid in C. There is no difference in C++.
However, you can typedef
the struct
in C, so you don’t have to write it every time.
typedef struct Node
{
int data;
struct Node *next; // we have not finished the typedef yet
} SNode;
SNode* cur = head; // OK to refer the typedef here
This syntax is also valid in C++ for compatibility.
这篇关于在功能参数struct关键字,有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文