typedef: A Quick Look
The typedef function 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 function 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 on ...
Get C Primer Plus®, Third Edition 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.