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
- typedef struct _tree tree;
- struct _tree
- {
- char data;
- tree *lchild,*rchild;
- tree *father;
- };
- typedef struct _tree
- {
- char data;
- struct _tree *lchild,*rchild;
- struct _tree *father;
- }tree;
阅读(1474) | 评论(0) | 转发(0) |