Typedef in C

typedef: is a reserved keyword in C and C++ language used to give any datatype an alias name.

Why we use typedef?

Normally, we use the standard name of data type like int, unsigned int, char, struct etc. to represent the feature of variable and function in the program. typedef replaced standard data types with an alias name whatever you want (prefer name according to variable function is best practice).

The C language contains the typedef keyword to allow users to provide alternative names for the primitive (e.g.,​ int) and user-defined​ (e.g struct) data types. Remember, this keyword adds a new name for some existing data type but does not create a new type.

Usage of typedef:

  • It increases the readability of the program.

  • It also reduces the complexity of the program.

Syntax: typedef  datatype  alias_name;