typedef Revisited

We have used the typedef keyword to create a new type, Boolean:
typedef int Boolean;
And then we declared variables of type Boolean:
Boolean flag;    // flag is a Boolean variable
We can use typedef to create other types in the same manner:
typedef int AgeList[10];
typedef float WeightList[20];
Then, we can declare variables of these new types:
AgeList ages;         // 10 integers, 0 - 9
WeightList weights;   // 20 floats, 0 - 19
If we didn't define any new types, we would have had to declare ages and weights like this:
int ages[10];
float weights[20];
This gives us a "shorthand" notation for declaring variables. This can be important when variable declarations become quite complex.

Previous page

Back to Lesson 11 Index
Back to Outline