C Typedef

A typedef declaration lets you define your own identifiers that can be used in place of type specifiers such as int, float, and double. A typedef declaration does not reserve storage. The names you define using typedef are not new data types, but synonyms for the data types or combinations of data types they represent.

Example 1

typedef int LENGTH;
LENGTH length, width, height;

typedef can also be used to define a struct type (structure, union, or C++ class). For example:

typedef struct 
{
                int scruples;
                int drams;
                int grains;
} WEIGHT;
 
//The structure WEIGHT can then be used in the following declarations:
 
WEIGHT  chicken, cow, horse, whale;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.