typedef

typedef keyword is used to assign a new name to any existing data-type.

For example, if we want to declare some variables of type unsigned int, we have to write unsigned int in a program and it can be quite hectic for some of us. So, we can assign a new name of our choice for unsigned int using typedef which can be used anytime we want to use unsigned int in a program.

Following is the syntax of typedef

typedef current_name new_name;

Now, suppose we want to declare two variables of type unsigned int. Instead of writing unsigned int again and again, let's use a new name uint in its place using typedef as follows:

typedef unsigned int uint;
uint i, j;

Now, we can write uint in the whole program instead of unsigned int. The above code is the same as writing:

First Student
roll no : 1
name : Brown
phone no : 123443
Second Student
roll no : 2
name : Sam
phone no : 1234567822
Third Student
roll no : 3
name : Addy
phone no : 1234567844

Here, the whole example is the same as we did in Structure, the only difference is that we wrote st in place of struct student i.e. we used the new type (named st) to declare the variables of this structure type (named student).

We can also use typedef with unions. For this, everything will be same as that of the structure with the keyword union in the place of struct.