Selecting a Number Type

Choosing the right type of number to use in a C application is critical, as it affects both the range of computational possibilities and the overall performance. Each of the available number types has its own strengths and weaknesses. More important, each has its own dangers, which can trip up even a thoughtful programmer.

C supports two broad types of numbers: integers (1, 2345, -8) and floating points (3.14, -0.8, 23.2). The latter always contain decimal points, whereas the former never do. Each of these is then further broken down into subtypes based on their size. Floats can also be represented as doubles, which are twice as accurate (more on this later). Also, integers (but not floats and doubles) can be defined as ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.