Using typedef
The typedef operator lets you rename a data type, like creating an alias. One of its main uses is to increase the portability of C applications: a common header file can include aliases to specific data types for different computers. By changing the particulars of the header file, the application should work on another system.
As an example, before the C99 standard supported the boolean type, you could have used typedef to create it yourself (which would store 0 or 1):
typedef int boolean; boolean correct;
The typedef operator can be used nicely with structures to simplify your declarations:
structure students { char name[30]; gpa float; };
The formal way to create a variable of this structure's type is
struct students timmy; ...
Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.