ABSTRACT

Section 7.1.2 mentioned several reasons for creating header files (.h files), including defining constants using #define, declaring functions, and defining new data types-usually referred to as “types”. This chapter explains how to define new types using structures. First let us consider what makes up a type by thinking about the differences between int and double. A type specifies: • The format for the data. For example, integers and double-precision floating-point

numbers are represented differently in the computer’s memory. • The range of possible values, and the size required to store the data. A 4-byte integer

stores valid values that are between the range of −2,147,483,648 (−231, approximately −109) and 2,147,483,647 (231− 1). In contrast, the absolute value of a double-precision floating number (8 bytes) can be as small as 10−308 and as large as 10308 (approximately). • The effect of operations on the data. Because the two types have different formats,

when a program has a statement a + b, the actual operations depend on whether a and b are integers or floating-point numbers. Also, some operations are restricted to certain data types. For example, switch must be used with an integer; double cannot be used in switch statements.