C++ data types(integer, real, char, Boolean and no type)

Lionsure 2020-09-06 Original by the website

C++ data types can be divided into: integer, real(floating point), char, Boolean and no type. Some types also include subtypes. The specific types, their lengths and value ranges are described in detail below.

It is worth noting that the range of data that can be represented by the basic data type is related to the compiler. The same type has different value ranges in different compilers.

 

C++ data types(integer, real, char, Boolean and no type)

One, integer

1. short int (short integer)

The short int is used to store short integers, ranging from -32768 to 32767, with a length of 2 bytes(8-bit integers).

 

2. unsigned short int

The unsigned short int is used to store unsigned short integers, ranging from 0 to 65535, with a length of 2 bytes(unsigned 8-bit integers).

 

3. int(integer)

The int is used to store integers, ranging from -2,147,483,648 to 2,147,483,647, with a length of 4 bytes(32-bit integers).

 

4. unsigned int (unsigned integer)

The unsigned int is used to store unsigned integers, the range is 0 to 4,294,967,295, and the length is 4 bytes(unsigned 32-bit integers).

 

5. long int(long integer)

The long int is the same as int, and it is reserved because the bytes taken on different platforms are different. On 16-bit platforms, int requires 2 bytes and long int requires 4 bytes; while on 32-bit platforms, they both use 4 bytes.

 

 

Two, Real type(floating point type)

1. float(single precision floating point type)

The float is used to store single-precision floating-point real numbers, the range is 1.18*10-38 to 3.40*1038, the length is 4 bytes(32 bits), and the precision is 7 bits.

 

2. double(double precision floating point type)

The double is used to store double-precision floating-point real numbers, the range is 2.23*10-308 to 1.79*10308, the length is 8 bytes(64 bits), and the precision is 15 bits.

 

3. long double(long double precision floating point type)

The long double is used to store long double-precision floating-point real numbers, ranging from 3.37*10-4932 to 1.18*104932, length 10 bytes(80 bits), and precision 19 bits.

 

 

Three, character type

1. char(character type)

The char is used to store characters, ranging from -128 to 127, with a length of 1 byte(8 bits).

 

2. unsigned char(unsigned character type)

The unsigned char is used to store unsigned characters, the range is 0 to 255, and the length is 1 byte (8 bits).

 

Four, bool(Boolean type)

The bool is used to store the boolean values true and false, generally with 1 bit storage.

 

 

Five, void(no type or "empty type")

The void means that the type has not yet been determined. When a variable of a determined type is assigned to it, it is the type of variable. It is a bit similar to the "Object" in C#, but it is actually for the needs of program