× Home (CS 211) Notes Projects Waxman's Website

General

typedef stands for type definition. This keyword allows us to form an alias for a datatype.
A type alias is a different name we can use to identify a type. For example, my name is Jia but I have an alias of Alex as well, both of which references the same person.
The syntax for using typedef is: typedef existing_type new_type_name ;
existing_type is any type that already exisit either fundamental or compound.
new_type_name is an new name that is given to the existing_type that will be used to identify it.

Example:

type1
box is now a datatype which refers to a 5 by 7 2D array of characters.
bb and wb are both of type box which mean they are both char[5][7], a 5 x 7 2D array of characters.
board is a 8 x 8 2D array of pointers to box types. Each cell of the board stores the address of some variable of type box.

NOTICE typedef DOES NOT created new distinct data types, it merely create synonyms of existing types.

Related: