您好,欢迎访问一九零五行业门户网

使用C语言中的typedef关键字来解释结构体

typedef‘c’允许使用‘typedef’关键字定义新的数据类型名称。使用‘typedef’,我们不能创建新的数据类型,而是为已经存在的类型定义一个新的名称。
syntaxtypedef datatype newname;
example 的中文翻译为:示例typedef int bhanu;int a;bhanu a; %d
this statement tells the compiler to recognize ‘bhanu’ as another name for ‘int’.‘bhanu’ is used to create another variable ‘a’ .‘bhanu a ‘declares ‘a’ as a variable of type ‘int’.example 的中文翻译为:示例#include <stdio.h>main (){ typedef int hours; hours h; //int h; clrscr (); printf("enter hours”); scanf ("%d”, &h); printf("minutes =%d”, h*60); printf("seconds = %d”, h*60*60); getch ();}
输出enter hours =1minutes = 60seconds = 360
typedefining一个结构的示例typedef struct employee{ int eno; char ename[30]; float sal;} emp;main (){ emp e = {10, "ramu”, 5000}; clrscr(); printf("number = %d”, e.eno); printf("name = %d”, e.ename); printf("salary = %d”, e.sal); getch ();}
输出number=10name=ramusalary=5000
以上就是使用c语言中的typedef关键字来解释结构体的详细内容。
其它类似信息

推荐信息