C typedef

In C Programming Language typedef ( type definition ) is a keyword allows us to create a alias for existing data types. Now we can declare variable using this alias instead of the data type. This alias is equivalent to the data type for which it is created.


It is easy to create alias, put the typedef keyword followed by the existing type name and the new name for that type.

Lets take look at example below:

We have created the alias for integer data type as “my_type”, now my_type behaves same as an integer.

Advantages of typedef

  • It makes the program more portable.
  • typedef make complex declaration easier to understand.

typedef with a struct

Take a look at below structure declaration

As we can see we have to include keyword struct every time you declare a new variable, but if we use typedef then the declaration will as easy as below

this way typedef make your declaration simpler.

typedef with union

typedef with enum