< Previous | Contents | Next >

Defining New Names for

Types

You can define a new name for an existing type. In fact, thats what I do next in the line:

typedef unsigned short int ushort;

This code defines the identifier ushort as another name for the type unsigned short int. To define new names for existing types, use typedef followed by the current type, followed by the new name. typedef is often used to create shorter names for types with long names.

You can use your new type name just like the original type. I initialize a ushort variable (which is really just an unsigned short int) named bonus and display its value.

24 Chapter 1 n Types, Variables, and Standard I/O: Lost Fortune