struct和typedef struct

在c语言里面:

typedef是类型定义的意思。typedef struct 是为了在c语言里面创建结构体变量更方便。
具体区别在于:

  • 若struct node {}这样来定义结构体的话。在申请node 的变量时,需要这样写,struct node n;
  • 若用typedef,可以这样写,typedef struct{}node; 在申请变量时就可以这样写,node n;

区别就在于使用时,是否可以省去struct这个关键字。

//usage of struct and typedef in c.
//ex1
struct node{
    int a;
    int *p;
};
struct node n;
//ex2
typedef struct{
    int a;
    int *p;
}node;
node n;

 


 

在c++里面:

可以直接struct node{};  申请变量时候直接 node n;

//usage of struct and typedef in c++.
struct node{
    int a;
    int *p;
};
node n;

 

posted @ 2016-09-27 09:36  Neptune15  阅读(292)  评论(0编辑  收藏  举报