Study Notes: data types to distinguish between different programming languages summary

Basic programming is also required core data type knowledge point, to be able to distinguish the different data types and data representation need to define data types. Different system or programming language, when you define data types may differ in the use of learning to distinguish, to avoid confusion, here I am a simple distinction between data and summary deepen the impression of it.

Java data types

Eight kinds of basic data types: byte, short, int, long, float, double, char, boolean.

Types of description range
byte 8, there is a symbol, a default value of 0 -2^7 - 2^7 -1
short 16-bit, signed, a default value of 0 -2^15-2^15 -1
int 32-bit, signed, a default value of 0 -2^31-2^31 -1
long 64-bit, signed, Default 0L -2^63-2^63 -1
float Single precision 32-bit, default values ​​0.0f
double 64-bit double precision, the default value 0.0d
char A single 16-bit Unicode characters \u0000-\uffff
boolean One bit, false / true true/false

Reference data types: arrays, classes, interfaces

C data types

C language has four types of data types

Types of Contained type
Basic data types ( Basic the Data Type ) char,int, float, double
Derived Data Types ( Derived the Data Type ) array, pointer, structure, union
Enumerated data type ( Enumeration the Data Type ) enum
Void data type ( void the Data the Type ) void

C language basic data types: memory size may vary according to the 32-bit or 64-bit operating system; not marked in the unsigned case, most are signed by default.

Types of description Value range
char 1 byte / 8, character type -128 to 127
unsigned char 1 byte / 8 bits, unsigned char 0 to 255
short The 2-byte / 16-bit short integer -32,768 to 32,767
unsigned short The 2-byte / 16-bit, unsigned short 0 to 65,535
int 4-byte / 32-bit, integer -2,147,483,648 to 2,147,483,647
unsigned int 4-byte / 32-bit, unsigned int 0 to 4,294,967,295
long 4-byte / 32-bit long integer -2,147,483,648 to 2,147,483,647
unsigned long 4-byte / 32-bit, unsigned long 0 to 4,294,967,2957
float 4 bytes significant digits 6-7 -3.4E-38 to 3.4E + 38
double 8 byte, 15 to 16 significant digits -1.7E-308 to 1.7E + 308
long double 16 bytes, 18 to 19 significant digits -1.2E-4932 to 1.2E + 4932

Note: C language itself is not bool type, generally with a substituted or custom int enumeration. However, inside the C99 standard, also defined bool type variable, as long as the introduction header <stdbool.h>, can be properly used in the C language type bool.

C ++ Data Types

Overall, the basic C ++ data types and C language almost.

Types of Keyword
Character char
Integer int
Float float/double
Boolean bool
Wide character wchar_t
Untyped void

You may use one or more types of modified modifiers: signed, unsigned, short, long.

Types of description range
char 8/1 byte -128 to 127 or 0 to 255
unsigned char 8/1 byte 0 to 255
int 32-bit / byte 4 -2147483648 to 2147483647
unsigned int 32-bit / byte 4 0-4294967295
short int 16/2 byte -32768 to 32767
unsigned short int 16/2 byte 0 to 65,535
long int 64/8 bytes -/+9,223,372,036,854,775,808
unsigned long int 64/8 bytes 0 to 18,446,744,073,709,551,615
float 4 bytes +/- 3.4e +/- 38 (~ 7 digits)
double 8 bytes +/- 1.7e +/- 308 (~ 16 digits)
long double 16 bytes +/- 1.2e +/- 4932 (~19 个数字)
wchar_t 2 或 4 字节 1 个宽字符

补充:在C/C++中可以使用sizeof()运算符返回数据类型所占的内存字节,32位系统和64位系统的结果可能是不同的。下面是一个简单的对比:

数据类型 32位编译器 64位编译器
char 1个字节 1个字节
char*(即指针变量) 4个字节 8个字节
short int 2个字节 2个字节
int 4个字节 4个字节
unsigned int 4个字节 4个字节
float 4个字节 4个字节
double 8个字节 8个字节
long 4个字节 8个字节
long long 8个字节 8个字节
unsigned long 4个字节 8个字节

Guess you like

Origin www.cnblogs.com/small-world/p/11622687.html