求大神细说一下typedef的理解,表示不太懂

SUNKMOON 2016-06-28 09:57:59
新人还在高中,,表示这个东西没太看懂,,,我给一段代码看看吧,,,

一个链栈里面,,有一个


struct stack_node
{
。。。。。。
};

typedef struct stack_node stack_list;
typedef stack_list *slink;

这里面的这个结构体类型是干什么用的

麻烦看看,,感激不尽

...全文
111 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
StevenV6 2016-06-29
  • 打赏
  • 举报
回复
就是以后定义结构体变量时直接用后面那个别名定义声明就好
赵4老师 2016-06-29
  • 打赏
  • 举报
回复
typedef typedef type-declaration synonym; The typedef keyword defines a synonym for the specified type-declaration. The identifier in the type-declaration becomes another name for the type, instead of naming an instance of the type. You cannot use the typedef specifier inside a function definition. A typedef declaration introduces a name that, within its scope, becomes a synonym for the type given by the decl-specifiers portion of the declaration. In contrast to the class, struct, union, and enum declarations, typedef declarations do not introduce new types — they introduce new names for existing types. Example // Example of the typedef keyword typedef unsigned long ulong; ulong ul; // Equivalent to "unsigned long ul;" typedef struct mystructtag { int i; float f; char c; } mystruct; mystruct ms; // Equivalent to "struct mystructtag ms;" typedef int (*funcptr)(); // funcptr is synonym for "pointer // to function returning int" funcptr table[10]; // Equivalent to "int (*table[10])();"
小灸舞 版主 2016-06-29
  • 打赏
  • 举报
回复
typedef struct stack_node stack_list;表示可以用stack_list替代struct stack_node
如:stack_list a等同于struct stack_node a;
typedef stack_list *slink;可以用slink替代stack_list *(注意*是跟着stack_list的)
如:stack_list *a等同于slink a;

http://www.cnblogs.com/afarmer/archive/2011/05/05/2038201.html
renwotao2009 2016-06-28
  • 打赏
  • 举报
回复
typedef给指定类型起一个别名

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧