About data types in C language

The units of storage size in C language are bit, byte, kb, mb, gb, tb, zb, pb, etc.
First of all, we need to understand that because the computer has positive and negative currents, so we will Negative transformation is used in binary, so a 0 or a 1 in the binary represents the size of a bit. For example, 11111111 such eight 1s is the size of eight bits. The conversion relationship between them is
1byte=8bit
1kb=1024byte
1mb=1024kb
1gb=1024mb
1tb=1024gb
1zb=1024tb
1pb=1024zb

In C language, we can know that there are such several data types, char, int, short, long, long long, float, double,
we can do an experiment in the program, first of all, sizeof calculates the amount of variables of the corresponding type The size of the memory is in bytes.
Insert picture description here
So we can get that
char corresponds to one byte, that is, eight bits, from 00000000 to 11111111, that is, from 0 to 255.
Short corresponds to two bytes, that is, the sixteen bit
int corresponds to four bytes, that is, the thirty-two bit
long corresponds to four bytes, because the C language specifies the long memory The size is >=int, which is different in different compilers, so the memory size of long is not necessarily larger than the memory size of int.
Long long corresponds to eight bytes, that is, sixty-four bits.
Float is four bytes, which is thirty-two bits.
Double is eight bytes, which is sixty-four bits.

There are some things worth knowing about floating-point numbers,
1 float a=1.5; this code is wrong, when directly inputting a decimal number like 1.5, the system default data type is double;
but you can write: float a= 1.5f; or double a=1.5;
2 When an operation such as 5/2=2.5 is to be performed. Make sure that at least one number is in floating-point format, such as 5.0/2 or 5/2.5, otherwise 5/2 is equal to 2, and the desired result cannot be obtained.
3 To keep several decimal places, it can be written as printf("%.5f",a); it means to keep five decimal places.

Guess you like

Origin blog.csdn.net/weixin_51306225/article/details/112678015