typedef 的用法

【2】typedef
(1)在C语言中,允许使用关键字typedef定义新的数据类型
其语法如下:
typedef <已有数据类型> <新数据类型>;
如:
typedef int INTEGER;
这里新定义了数据类型INTEGER, 其等价于int
INTEGER i; <==> int i;
(2) 在C语言中经常在定义结构体类型时使用typedef,例如
typedef struct _node_
{
int data;
struct _node_ *next;
} listnode, *linklist;
这里定义了两个新的数据类型listnode和linklist。其中listnode
等价于数据类型struct _node_ 而 linklist等价于struct _node_ *






#include <stdio.h> /* typedef struct node{ int data; struct node *next; //嵌套结构体 }listnode,*linklist; ///这个地方可以重命名,可以定义结构体名或者结构体指针,可以定义2个哦 */ struct node{ int data; struct node * next; }; typedef struct node listnode; typedef struct node *linklist;//typedef listnode *linklist; int main(int argc, const char *argv[]) { //struct node n1,n2,*p; // -----1 //listnode n1,n2,n3,*p; // -----2 listnode n1,n2,n3; linklist p; // -----3 n1.data = 10; n1.next = NULL; n2.data = 20; n2.next = NULL; n3.data = 40; n3.data = NULL; p = &n1; return 0; }
原文地址:https://www.cnblogs.com/jack-hzm/p/10099253.html