Chinaunix首页 | 论坛 | 博客
  • 博客访问: 360477
  • 博文数量: 79
  • 博客积分: 1270
  • 博客等级: 中尉
  • 技术积分: 1370
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-12 08:48
个人简介

freedom~~~~~~~~~~

文章分类

全部博文(79)

文章存档

2014年(10)

2013年(2)

2012年(13)

2011年(54)

分类: C/C++

2012-10-31 15:59:02

typedef is one keyword of C lanuage.
It's used for define a new name of a data type. The data type include (int , char , and struct ...).

In the program,there can be two main use for this word. One is give a variable a lucid name.
The other is simplify some struct.

1,The simplest use of this word.
typedef long byte_4;
    give the known data type long a new lucid name.byte_4.
2, Typedef and struct.
typedef struct tagMyStruct
{
int a;
long b;
}Mystruct;

The code above include two means
1- define a new data type.
struct tagMyStruct
{
int a;
long b;
}
So keyword struct and tagMyStruct consitute the new data type. No matter about typedef, the data type is there.

We can use "struct tagMySturct" to define a new variable.But simple use tagMyStuct is wrong,because "struct" and "tagMyStruct" consitute
the new data type.
2- new name for the struct

typedef struct tagMyStruct MySturct;
So we can just MyStruct to define new variable.
----------------------------------------------------------------------------------------------------
C language can use it's own ptr in it's struct.


below is right

点击(此处)折叠或打开

  1. typedef struct _tree tree;
  2. struct _tree
  3. {
  4.     char data;
  5.     tree *lchild,*rchild;
  6.     tree *father;
  7. };


  8. typedef struct _tree
  9. {
  10.     char data;
  11.     struct _tree *lchild,*rchild;
  12.     struct _tree *father;
  13. }tree;

阅读(1474) | 评论(0) | 转发(0) |
0

上一篇:再见了,曾经的爱情

下一篇:二叉排序树

给主人留下些什么吧!~~