C Language Types

A type defines the size of the memory area that a variable of this type would occupy. It also defines how a variable of this type can be used - which operations are legal on this type. And last but not least does a type define a name as a reference to it. C types are either primitives (int, char, long) or composite (struct, union). The composite types are built from primitive types.

Example 1. Structs in C

struct controller {
                                   unsigned char output;
                                   unsigned char input;
                                   unsigned int control;
                          };

Note

The actual size of a variable in memory is also determined by the so-called "alignment": Rules on which memory addresses certain types can start. This leads sometimes to "padding" bytes - empty areas within or between types. Compiler arguments control the alignment.