O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required