Struct

When starting to learn the binary tree, I find that I am not clear with the struct.So here comes this note.

First, when it comes to Struct, it may like this.

struct Table{

      int legs;

      char name;

};

However, mostly we use it like this.

typedef struct Table{

int legs;

struct Table *next;

char name;

}Table,*TableList;

so, what does typedef, Table,*TableList mean?

if you use typedef in the code above, it means the Table[structure tag] could be used to create Struct type variable like      Table t;  t.legs=4;   the Table behalf of the structure.                                                                                          

if there is no typedef, you have to write      struct Table t      each time you create a structure type variable

The difference is to write struct or not, that typedef brings.


if we omit the structure tag,

typedef struct {

int legs;

struct Table *next;

char name;

}Table,*TableList;

the Table is the only one structure entity we could use.


The *TableList is a structure pointer, a pointer point to the struct node. 



Things get different in C++

typedef struct Table{

int legs;

}Table1;

The Table1 is a structure entity , use 

Table1 t; 

t.legs=4; 


struct Table{

int legs;

}Table2;

TheTable2 is a structure variable, use 

Table2.legs=4;


updating ........

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,029评论 0 23
  • 白茅依依兮,露染芒; 南山幽幽兮,雾锁光; 榛林欣欣兮,黄鸟藏; 秋水浥浥兮,鹤立央。 双目炯炯兮,瞳玉镶; 顶红...
    静铃音阅读 1,057评论 55 42
  • 人们访问一个网站可能处于以下三个原因:1、寻找某个东西2、想完成某项任务3、想消磨一会时间 基于此,用户在访问一个...
    7win7阅读 177评论 0 0
  • 领导让我写公司报纸的评论员文章时我是内心崩溃的,对于上大学以后基本就“绝笔”的我来说写一篇党政方向的文章真...
    noora_df40阅读 180评论 0 2