C++ supports three kinds of object types:
Fundamental types are built into the language (such as int, float, or
double). Instances of these fundamental types are often called
“variables” .
Derived types
are new types derived from built-in types.
Class types are new types created by combining existing types.
Fundamental Types of the C++ Language
Fundamental Types of the C++ Language
Category
|
Type
|
Contents
|
Integral
|
char
|
Type char is an integral type that usually contains members of
the execution character set — in Microsoft C++, this is ASCII.
|
The C++ compiler treats variables of type char, signed char,
and unsigned char as having different types. Variables of type char
are promoted to int as if they are type signed char by
default, unless the /J compilation option is used. In this case they are
treated as type unsigned char and are promoted to int
without sign extension.
|
||
short
|
Type short int (or simply short) is an integral
type that is larger than or equal to the size of type char, and
shorter than or equal to the size of type int.
|
|
Objects of type short can be declared as signed short
or unsigned short. Signed short is a synonym for short.
|
||
int
|
Type int is an integral type that is larger than or equal to
the size of type short int, and shorter than or equal to the
size of type long.
|
|
Objects of type int can be declared as signed int
or unsigned int. Signed int is a synonym for int.
|
||
Long
|
Type long (or long int) is an integral type that
is larger than or equal to the size of type int.
|
|
Objects of type long can be declared as signed long
or unsigned long. Signed long is a synonym for long.
|
||
Floating
|
float
|
Type float is the smallest floating type.
|
double
|
Type double is a floating type that is larger than or equal to
type float, but shorter than or equal to the size of type long double.
|
|
long double
|
Type long double is a floating type that is equal to
type double.
|
Sizes of Fundamental Types
Type
|
Size
|
char, unsigned
char, signed char
|
1 byte
|
short, unsigned
short
|
2 bytes
|
int, unsigned
int
|
4 bytes
|
long, unsigned
long
|
4 bytes
|
float
|
4 bytes
|
double
|
8 bytes
|
long double
|
8 bytes
|
No comments:
Post a Comment