6.3. Variables and Data Types

The main functions in the previous sections demonstrate that even the simplest of C programs include operations on data, even if it is just writing it to the program output. Any non-trivial program needs to be able to represent different types of data, and reference it in a way that a programmer can understand. C has many built in data types, including integer, decimal, and character types. To store and reference data, C has variables, which are labels applied to pieces of data.

You should already recognize the fundamental integer type of C: int. It appeared in the previous sections as the type of the variable argc. An int is a whole number that can be positive, negative, or zero. There are also other variations on the integer, including integers that cannot take negative values (unsigned int), integers that take up less space but have a more restricted range of values (short int), and integers that take up more space but can take a wider range of values (long int). The following table provides the most important integer types in C.

Integer TypeMinimum ValueMaximum ValueSize in Bytes
short int−32768327672
long int−214748364821474836474
unsigned int042949672954

There are other variations on these types, but these are by far the most important and the ones you will encounter the most.

Now that you know what integer types are available, it would be nice to know how you use them. You can create integer literals in your code, which ...

Get Beginning Mac OS® X Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.