Basic Integer Data Type in C Language
The family of integer types include character, short integer, integer, and long integer. They are all divided into two versions: signed and unsigned.
Rules on the size of integer values:
A long integer must be at least the same length as an integer, and an integer must be at least the same length as a short integer.
Generally, the size of various types on 32-bit and 64-bit machines
Long, unsigned long pointer is the full font length of the machine. In fact, the size of these types is the same as the number of CPU digits. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + z8LD5rXEs8zQ8srH1NpYODa83Lm5u7e + digest + CjxwcmUgY2xhc3M9 "brush: java;" >#include Int main () {printf ("the char range is %-20hhd ~ % 20hhu, size is % u \ n ", 0x80, 0x7f, sizeof (char); printf (" the usigned char range is %-20hhu ~ % 20hhu, size is % u \ n ", 0x0, 0xff, sizeof (unsigned char); printf (" the short range is %-20hd ~ % 20hu, size is % u \ n ", 0x8000, 0x7fff, sizeof (short); printf (" the unsigned short range is %-20hu ~ % 20hu, size is % u \ n ", 0x0, 0 xffff, sizeof (unsigned short); printf (" the int range is %-20d ~ % 20u, size is % u \ n ", 0x80000000, 0x7fffffff, sizeof (int); printf (" the unsigned int range is %-20u ~ % 20u, size is % u \ n ", 0x0, 0 xffffffff, sizeof (unsigned int); printf (" the long range is %-20ld ~ % 20lu, size is % u \ n ", 0x80000000, 0x7fffffff, sizeof (long); printf (" the unsigned long range is %-20lu ~ % 20lu, size is % u \ n ", 0x0, 0 xffffffff, sizeof (unsigned long); printf (" the llong range is %-20lld ~ % 20llu, size is % u \ n ", 0x8000000000000000, 0x7fffffffffffffff, sizeof (long); printf (" the unsigned llong range is %-20lld ~ % 20llu, size is % u \ n ", 0x0ll, 0 xffffffffffffff, sizeof (unsigned long )); printf ("default constant size is % u \ n", sizeof ('B'), sizeof (0x0), sizeof (0x0ll ));}
Running result
The char range is-128 ~ 127, size is 1
The usigned char range is 0 ~ 255, size is 1
The short range is-32768 ~ 32767, size is 2
The unsigned short range is 0 ~ 65535, size is 2
The int range is-2147483648 ~ 2147483647, size is 4
The unsigned int range is 0 ~ 4294967295, size is 4
The long range is-2147483648 ~ 2147483647, size is 4
The unsigned long range is 0 ~ 4294967295, size is 4
The llong range is-9223372036854775808 ~ 9223372036854775807, size is 8
The unsigned llong range is 0 ~ 18446744073709551615, size is 8
Default constant size is 4 4 8
Integer literal value (integer constant)
The term nominal value is the abbreviation of a literal value constant ------ this is an entity that specifies its own value and cannot be changed.
When an integer constant occurs in a program, which of the following types belongs to the family of integers? The answer depends on how constants are written. You can add a suffix after some constants to change the default rule. Add L or l after an integer constant so that the integer can be interpreted as a long integer value. The character U or u is used to specify the value as an unsigned integer value, if one of the two characters is added after a constant, it is interpreted as an unsigned long integer value. For character constants. Their type is always int. You cannot add unsigned or long suffixes to them.
In C language, the default integer constant (character constant/integer constant) type is int,
If the formatted character % llu is used, printf determines that the value to be output is 8 bytes in size, so if the corresponding parameter is 0x0, it may print out a mess (because it reads 8 bytes instead of 4 bytes)
In addition, when a printf integer variable is printed, whether it is signed or unsigned depends on the format character, and is irrelevant to the actual input parameter type and symbol.
For example
Int I = 0x80001010;
Printf ("% d \ n", I); print-2147479536
Printf ("% u \ n", I); print 2147487760
Printf ("% hu \ n", I); print 4112 high two digits are truncated, the actual printing is 0x1010
Printf ("% hhu \ n", I); print 16 third-digit truncated, the actual print is 0x10
Therefore, please remember that printing the variable size with printf has nothing to do with the symbol itself, even if the conversion is strong! Select the correct format characters