The typedef Keyword

C++ provides the typedef keyword to allow you to give a new name (or synonym) to an existing data type, with the object of making the source code easier to follow. The syntax for using the typedef keyword is as follows:

typedef type new_type_name;

Consider the following code fragment:

typedef int qty;
typedef string desc;
qty num_widgets;
desc desc_widgets;
num_widgets ++;
if (num_widgets == 10)

Here, we have created two type identifiers, qty and desc, which which can be used to declare an integer (int) variable and a string variable respectively. We use typedef, essentially, to define an alias for an existing type.