We have seen that C provides a number of different data types, char for characters, int for integers, float for floating point and so on. I have also said that you should pick the "smallest" data type for any given job, i.e. if you know that you will not need to hold values greater than 200 in a variable you should use a char variable.

This means that the C language has an idea of the size of each data type. The size is measured in storage locations which are usually 1 byte. C uses these sizes to work out how far down memory to move when going from one element to another. When I increment the subscript to move down my array it is important that move to the next valid element, not just the next storage location.

In the diagram on the right you can see that the variable i takes up two storage locations. In the PICmicro microcontroller there are just two sizes of variable, 8 bit values (char) which are held in a single location, and 16 bit values (int) which are held in two locations. Note that these sizes are not common to all C versions of C.

 


i is a 16-bit value, and therefore takes up two memory locations