O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

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

typedef: A Quick Look

The typedef facility is an advanced data feature that enables you to create your own name for a type. It is similar to #define in that respect, but with three differences:

  • Unlike #define, typedef is limited to giving symbolic names to types only and not to values.

  • The typedef interpretation is performed by the compiler, not the preprocessor.

  • Within its limits, typedef is more flexible than #define.

Let's see how typedef works. Suppose you want to use the term BYTE for one-byte numbers. You simply define BYTE as if it were a char variable and precede the definition by the keyword typedef.

typedef unsigned char BYTE;

From then on, you can use BYTE to define variables:

BYTE x, y[10], * z;

The scope of this definition depends ...

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