3 Data Types

The type of a data object in C determines the range and kind of values an object can represent, the size of machine storage reserved for an object, and the operations allowed on an object. Functions also have types, and the function's return type and parameter types can be specified in the function's declaration.

The following sections discuss these topics:

The selection of a data type for a given object or function is one of the fundamental programming steps in any language. Each data object or function in the program must have a data type, assigned either explicitly or by default. (Chapter 4 discusses the assignment of a data type to an object.) C offers a wide variety of types. This diversity is a strong feature of C, but can be initially confusing.

To help avoid this confusion, remember that C has only a few basic types. All other types are derived combinations of these basic types. Some types can be specified in more than one way; for example, short and short int are the same type. (In this manual, the longest, most specific name is always used.) Type is assigned to each object or function as part of the declaration. Chapter 4 describes declarations in more detail.

Table 3-1 lists the basic data types: integral types (objects representing integers within a specific range), floating-point types (objects representing numbers with a significand part-a whole number plus a fractional number-and an optional exponential part), and character types (objects representing a printable character). Character types are stored as integers.


Note
Enumerated types are also normally classified as integral types, but for the purposes of clarity they are not listed here. See Section 3.6 for more information.

Table 3-1 Basic Data Types

Integral Types  Floating Point Types 
short int   float  
signed short int   double  
unsigned short int   long double  
int    
signed int    
unsigned int    
long int    
signed long int    
unsigned long int    
Integral Character Types   
char    
signed char    
unsigned char    

The integral and floating-point types combined are called the arithmetic types. See Section 3.1 for information about the size and range of integral and floating- point values.

A large variety of derived types can be created from the basic types. Section 3.4 discusses the derived types.

Besides the basic and derived types, there are three keywords that specify unique types: void , enum , and typedef :

There are also the type-qualifier keywords:

Using a qualifying keyword in the type declaration of an object results in a qualified type. See Section 3.7 for general information on type qualifiers.

With such a wide variety of types, operations in a program often need to be performed on objects of different types, and parameters of one type often need to be passed to functions expecting different parameter types. Because C stores different kinds of values in different ways, a conversion must be performed on at least one of the operands or arguments to convert the type of one operand or argument to match that of the other. You can perform conversions explicitly through casting, or implicitly through the compiler. See Section 6.10 for more information on data-type conversions. See Section 2.7 for a description of type compatibility.

See your platform-specific DEC C documentation for a description of any implementation-defined data types.


Previous Page | Next Page | Table of Contents | Index