O'Reilly logo

Beginning Mac OS® X Programming by Drew McCormack, Michael Trent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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
int−214748364821474836474
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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required