
Typedef
‘C’允许使用‘typedef’关键字定义新的数据类型名称。使用‘typedef’,我们不能创建新的数据类型,而是为已经存在的类型定义一个新的名称。
Syntax
typedef 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 =1 Minutes = 60 Seconds = 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=10 Name=ramu Salary=5000











