previous | start | next

Using typedef to Name Union or Struct Types

The typedef declaration is used to give a name to a type expression without declaring a variable.

Example 1. Define the name intptr to be the type pointer to
int:

typedef int * intptr;

Example 2. Define the name pair to be a struct with no tag,
but with two int's:

typedef struct { int x; int y; } pair;

Example 3. Define the name number to be a union with no tag,
but with either an int or a float (sharing the same storage):

typedef union { int x; float y; } number;



previous | start | next