type-defined structure in C ?


The structure definition associated with keyword typedef is called type defined structure. This is the most powerful way of defining the structure.

Syntax:-
typedef struct
{
type 1;
type 2;
}TYPE_ID;


Example of typedef structure:-
 void main()
 {
 typedef struct
 {
 int roll;
 char name[10];
 }stu1,stu2;
 printf(“enter roll of 2 student”);
 scanf(“%d%d”,&stu1.roll,&stu2.roll);
 printf(“enter name of two student”);
 scanf(“%s%s”,stu1.name,stu2.name);
 printf(“%d%d”, stu1.roll,stu2.roll);
 printf(“%s%s”,stu1.name,stu2.name);
 getch();
 }