1. Other integer types int is the basic integer type of the C language, which satisfies our need to process general data. The C language also provides four keywords that can be modified int: Short,long,signed, and unsigned. Using these four keywords, the C language standard defines the following integer types: 1 short Int (abbreviated to short), like int, also signed integers 2 Long Int (abbreviated: Long), signed integer 3 Long int (short: Long Long), C99 the standard added type, Signed integers 4 unsigned int (abbreviation: unsigned), unsigned integer, cannot represent negative numbers 5) unsigned long int (abbreviated: unsigned long), unsigned integer, Cannot represent negative numbers 6 unsigned short int (abbreviated: unsigned short), unsigned integer, Cannot represent negative numbers 7) unsigned long int (abbreviated: unsigned long), C99 added type, unsigned integer 8 all integer types that do not indicate unsigned are signed integers by default. In front of these integer types, add signed to make the reader more aware These are signed integers, although there are no signed representing signed integers. For example: Signed int is equivalent to int. In general, we call short an integer , a long length , and a long long as a long integer, and an int as an integral type . The integer types that begin with unsigned are collectively called unsigned integers. For example: We call unsigned short as an unsigned integer . Analogy 2. Declaration mode These integer types are declared in the same way as the int type. For example: long int estine; Long Johns; short int erns; Short ribs; unsigned int s_count; Unsigned players; unsigned long headcount; unsigned short yesvotes; Long long ago; / * C99 Unique * * unsigned long long ego; / * C99 Unique * * If your compiler does not support the C99 standard, you cannot use long long and unsigned longlong. 3. Value range (representation range) The standard also stipulates that these integer types ofminimum range of values。 The minimum representation range for short is the same as int-32767 to 32767. i.e.-(2^15-1) to (2^15-1). Among them, 2^15 represents 2 of the 15-time side. Similarly, 2 of the 20 times are written as 2^20, and so on. Note: C language 2^15 does not mean 2 of the 15 times, in order to write conveniently, we would like to say so. The minimum range for a long is-2147483647 to 2147483647. i.e.-(2^31-1) to (2^31-1). The minimum representation range for unsigned short is the same as the unsigned int, which is 0 to 65535 (2^16-1). The minimum range of unsigned long is 0 to 4294967295 (2^32-1). The minimum range for a long long is-9223372036854775807 (-(2^63-1)) to 9223372036854775807 (2^63-1); unsigned long long is 0 to 18446744073709551615 (2^64-1). Standard specification, int's representation rangecannot be less thanThe representation range of short, the range of longcannot be less thanThe representation range of Int. This means that a short variable may occupy less space than an int variable, while a long variable may occupy more space than an int variable. In a 16-bit computer, int and short are typically 16-bit, and long is a 32-bit 32-bit computer where short is generally 16, while long and int are 32 bits. TC2 (16-bit compiler), int is 16-bit, and dev-c++ (32-bit compiler), int is 32-bit. Variables declared using the unsigned int can only represent positive integers. If the int is 16 digits, then the unsigned int representation range is 0 to 65535 (2^16-1). This is because the unsigned does not require a symbol bit and can use all 16 bits to represent integers. and int needs a bit assign Bit, used to indicate positive and negative, and only 15 bits are used to represent integers. Currently, long long is 64 digits, long is 32 bits, short is 16 bits, and int or 16 bits, or 32 bits. The exact number of bits that a compiler uses to represent these types, we can useoperatorsizeof to get. For example: printf ("%lu\n", (unsigned long) sizeof (int) * 8); / * The number of digits to output int printf ("%zu\n", sizeof (short) * 8); / * The number of digits to output short * * sizeof's usage we'll talk about it later, so just have an impression. The %zu in the second sentence is C99 specific, such as the results of your compiler does not support C99 (precisely, if your compiler uses a library function that does not support C99), the result of the run will be an error. 4. Selection of integer types If you're dealing with just a positive integer , you should prioritize those integer types that start with unsigned. If you are dealing with an integer that is outside the range that int can represent, and long has a representation range larger than int in your compiler, use long. However, if not necessary, try not to use long, as it may reduce the efficiency of the program. One thing to note: If you have a compiler in which both long and int are 32-bit, and you need to use a 32-bit integer, you should use long instead of Int. Only in this way can our programs be safely ported to 16-bit computers, becauseint is generally 16-bit in 16-bit computers. Similarly, if you need to use a 64-bit integer, it's a long long. If int is a bit, then using short can save space, but you have to make sure that the integer you are working on does not exceed the short representation range . This "savings" is meaningless for computers with large memory.
5. long constants and long long constants in general, integer constants are stored as int types. If we use an integer constant that exceeds the representation of intscope, the C language requires the compiler to automatically use unsigned int to handle this constant. If unsigned is not enough to indicate that thisconstant, the compiler will use a long. If that's not true, then use unsigned long,long long, in turn ., unsigned long long. If unsigned long long is not the case, then the compiler is out of the means. Note: LongLong and unsigned long long are C99 specific. For example, if an int is 16 digits, it will not represent a constant1000000. The compiler uses long to handle this constant, because unsigned int does not represent 1000000. Similarly, hexadecimal and octal integer constants are usually also treated as int. However, when we use constants that exceed theafter the scope of the int is represented, the compiler uses unsigned int,long,unsigned long,long long andunsigned long long. Until the type used is sufficient to represent that constant. Sometimes we use smaller constants, but we want this constant to be treated as long, which requires aThe constant is followed by the suffix l (lowercase letter L) or L (capital letter L). We should avoid using L, because L easy andThe number 1 is confusing. For example, an integer constant of 7 is handled as an int, but an integer constant of 7L (or 7l) is taken aslong to deal with. Similarly, after the integer constant plus the suffix ll or ll, the constant is treated as a long longto deal with. For example: 3LL. If you want to use unsigned integer constants, you should also use the suffix u or u. For example: 2u,3u,4lu,5ul,6lu,7llu,8ull,9ull. These suffixes can also be used for hexadecimal and octal integer constants. For example: 020L,010LL, 0x30ul,0x40ull. |