Home  >  Article  >  What are the data types?

What are the data types?

coldplay.xixi
coldplay.xixiOriginal
2021-01-28 17:16:30266218browse

Data types include: 1. Integer type [byte, short, int, long]; 2. Floating point type [float, double]; 3. Character type char; 4. Boolean type boolean.

The operating environment of this article: Windows10 Home Chinese version, Acer S40-51 computer.

Free recommendation: Programming video course

The data types are:

1) Four integer types ( byte, short, int, long):

  • byte: 8 bits, used to represent the smallest data unit, such as data in a file, -128~127

  • short: 16 bits, rarely used, -32768 ~ 32767

  • int: 32 bits, most commonly used, -2^31-1~2^31 (2.1 billion)

  • long: 64 bits, commonly used

Notes: int i=5; // 5 is called a direct quantity ( or literal), that is, a constant written directly.

Integer literals are of type int by default, so add L or l after the defined long data.​

Variables less than 32 digits are calculated as int results.​

Forced operators have higher priority than mathematical operators. See Constants and Variables for examples.

2) Two types of floating point numbers (float, double):

float: 32 bits, suffix F or f, 1 sign bit, 8-bit exponent, 23 valid mantissas.

double: 64 bits, most commonly used, suffix D or d, 1 sign bit, 11 bits of exponent, 52 bits of effective tail

Notes:

Binary floating point number : 1010100010=101010001.0*2=10101000.10*2^10 (2nd power)=1010100.010*2^11 (3rd power)= . 1010100010*2^1010 (10th power)

Mantissa: . 101010001 0

Exponent: 1010

Base: 2

Floating point numeric values ​​are of double type by default, so add F or f after the defined float type data; double type is not required Write the suffix, but be sure to write D or X. The range of

float is larger than long and the exponent can be very large.​

Floating point numbers are inexact, and floating point numbers cannot be accurately compared.

3) A character type (char):

char: 16 bits, an integer type, 1 character enclosed in single quotes (can be a Chinese characters), using Unicode code to represent characters, 0~2^16-1 (65535).​

Note: Cannot be 0 characters.

Escape characters: \n Line feed \r Carriage return \t Tab character \" Double quotation mark \\ represents a \

Two characters char are connected with " " in the middle, and the characters are converted internally first into int type, and then perform addition operation, char is essentially a number! Binary, when displayed, it is "processed" and displayed as characters.

4) A Boolean type (boolean): true True and false.

5) Type conversion:

char--> Automatic conversion: byte-->short-->int -->long-->float-->double                                                                                                                                                                                                                                          through

##6) Memory:

8 bits: Byte (byte type) 16 bits: short (short integer type), char (character type)

32-bit: int (integer), float (single-precision/floating-point)

64-bit: long (long integer), double (double-precision)

Last one: boolean Boolean type

Related free learning recommendations:

php programming(Video)

The above is the detailed content of What are the data types?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn