"typedef" is a keyword,which is used to give a new name of datatype.
Syntaxtypedef datatype name;
here,"datatype" like int, float, struct, array etc and,"name" contains new name of datatype.
Example#include<stdio.h> int main() { typedef int num; num n; scanf("%d",&n); printf("%d",n); return 0; }
Here the new name of 'int' is num.
Note:- It is mainly used with user defined datatype like(structure,union,enumration).
#include<stdio.h> #include<string.h> typedef struct student { char name[50]; int roll_no; char subject[15]; float percentage; } STUDENT; int main( ) { STUDENT st1; strcpy(st1.name, "Vikas kumar"); strcpy(st1.subject, "C Programming"); st1.roll_no=183481361; st1.percentage=76; printf( "Name : %s\n", st1.name); printf( "Roll No : %d\n", st1.roll_no); printf( "Subject : %s\n", st1.subject); printf( "Percentage: %f\n", st1.percentage); return 0; }