admin管理员组文章数量:1794759
C语言学习笔记—type关键字
typedef为C语言的关键字,作用是为一种数据类型定义一个新名字。 这里的数据类型包括内部数据类型(int,char等)和自定义的数据类型(struct等)。 使用typedef定义新类型的方法:在传统的变量声明表达式里用 (新的)类型名 替换变量名,然后把关键字typedef加在该语句的开头即可。 例:
#include <stdio.h> #include <stdlib.h> typedef unsigned char u_int8; typedef unsigned short int u_int16; typedef unsigned int u_int32; typedef struct Student { char *name; int score; }stu,*Pstu; int main() { u_int8 data = 16; u_int16 data1 = 17; u_int32 data2 = 18; stu stu1; stu1.score = 100; Pstu pstu; pstu = (Pstu)malloc(sizeof(stu)); pstu->score = 12; printf("%d\\n",stu1.score); printf("%d\\n",pstu->score); printf("%d,%d,%d\\n",data,data1,data2); system("pause"); return 0; }作用:
版权声明:本文标题:C语言学习笔记—type关键字 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686628445a88190.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论