A data object is a region of storage that
contains a value or group of values. Each value can be accessed using
its identifier or a more complex expression that refers to the object.
In addition, each object has a unique data type.
The data type of an object determines the storage allocation for that
object and the interpretation of the values during subsequent access.
It is also used in any type checking operations. Both the identifier
and data type of an object are established in the object declaration.
An instance of a class type is commonly
called a class object. The individual class
members are also called objects. The set of all member objects comprises
a class object.
Data types are often grouped into type categories that overlap,
such as:
- Fundamental types versus derived types
- Fundamental data types are also known
as "basic", "fundamental" or "built-in" to the language. These include
integers, floating-point numbers, and characters. Derived types, also known as "compound" types in Standard
C++, are created from the set of basic types, and include arrays,
pointers, structures, unions, and enumerations. All
C++ classes are considered compound types.
- Built-in types versus user-defined types
- Built-in data types include all of the
fundamental types, plus types that refer to the addresses of basic
types, such as arrays and pointers. User-defined types
are created by the user from the set of basic types, in typedef,
structure, union, and enumeration definitions. C++
classes are considered user-defined types.
- Scalar types versus aggregate types
- Scalar types represent a single
data value, while aggregate types represent
multiple values, of the same type or of different types. Scalars include
the arithmetic types and pointers. Aggregate types include arrays
and structures. C++ classes are considered
aggregate types.
The following matrix lists the supported data types and their
classification into fundamental, derived, scalar, and aggregate types.
Table 9. C/C++ data types
Data object |
Basic |
Compound |
Built-
in
|
User-
defined
|
Scalar |
Aggregate |
integer types |
+ |
|
+ |
|
+ |
|
floating-point types |
+ |
|
+ |
|
+ |
|
character types |
|
|
+ |
|
+ |
|
Booleans |
+ |
|
+ |
|
+ |
|
void type |
+1 |
|
+ |
|
+ |
|
pointers |
|
+ |
+ |
|
+ |
|
arrays |
|
+ |
+ |
|
|
+ |
structures |
|
+ |
|
+ |
|
+ |
unions |
|
+ |
|
+ |
|
|
enumerations |
|
+ |
|
+ |
see note2 |
|
classes |
|
+ |
|
+ |
|
+ |
typedef types |
|
+ |
|
+ |
|
|
Notes:
- The void type is really an incomplete type, as discussed
in Incomplete types. Nevertheless,
Standard C++ defines it as a fundamental type.
-
The C standard does not classify
enumerations as either scalar or aggregate.
Standard
C++ classifies enumerations as scalars.