Typedef - Defining Type
Whenever we create a structure then we are treated it as new type of data. In C programming a keyword called typedef gives you facility to rename data type.
Consider the following example - Suppose we are storing only roll numbers then it would be very useful and meaningful if we have data type “roll”.
Defining Type in C using typedef :
#include<stdio.h> int main() { typedef int Roll; Roll num1 = 40,num2 = 20; printf("Roll number 1 : %d",num1); printf("Roll number 2 : %d",num2); return(0); }
Explanation of Typedef :
In the above program we want to give another name to an integer data type i.e “roll”. We can do this using typedef statement as below -
typedef int Roll; Roll num1 = 40,num2 = 20;
However we can also use integer data type after we create another data type “Roll”. typedef would just create similar data type.
In the further chapter (in Structure) we will again go through this chapter in details.