In C typedef is a keyword.
Keyword typedef stands for type definition.
It is used for create an alias name of existing data type. typedef is used by writing the keyword typedef, followed by the existing data type and then the new name.
typedef existing_daya_type new_name ;
typedef char ch;
In above example, i has defined ch as char, so now i could perfectly use ch as declarations of any other valid types:
Note:- typedef does not create different types. It only create synonyms of existing data types i.e. in our example the type of mychar can be considered to be either ch or char, since both are in fact the same type.
Example of typedef:
typedef int num;
/*c program for shows the use of typedef data type */
typedef int number;
printf("Enter n1 : ");
printf("Enter n2 : ");
printf("sum of n1+n2 = %d",sum);
/*************** OUTPUT ***************/
|Example of typedef|
typedef can be useful to define an alias for a type that is frequently used within a program.
typedef is also useful to define types when it is possible that we will need to change the type in later our program.
typedef is also used when existing_name is too large or confusing.