Major operating system experiment progress (3) ----- number of bytes of common data types in C ++

Source: Internet
Author: User

Char-128 ~ + 127 (1 Byte) short-32767 ~ + 32768 (2 Bytes) unsigned short 0 ~ 65536 (2 Bytes) int-2147483648 ~ + 2147483647 (4 Bytes) unsigned int 0 ~ 4294967295 (4 Bytes) double 1.7*10 ^ 308 (8 Bytes) long (= int)-2147483648 ~ + 2147483647 (4 Bytes) long-9223372036854775808 ~ + 9223372036854775807 (8 Bytes) Dev-C ++ basic types of digits and value range: symbol attribute Length attribute basic type occupied by the number of digits Value Range Input operator example output character example -- char 8-2 ^ 7 ~ 2 ^ 7-1% c % c, % d, % usigned -- char 8-2 ^ 7 ~ 2 ^ 7-1% c % c, % d, % uunsigned -- char 8 0 ~ 2 ^ 8-1% c % c, % d, % u [signed] short [int] 16-2 ^ 15 ~ 2 ^ 15-1% hdunsigned short [int] 16 0 ~ 2 ^ 16-1% hu, % ho, % hx [signed] -- int 32-2 ^ 31 ~ 2 ^ 31-1% dunsigned -- [int] 32 0 ~ 2 ^ 32-1% u, % o, % x [signed] long [int] 32-2 ^ 31 ~ 2 ^ 31-1% ldunsigned long [int] 32 0 ~ 2 ^ 32-1% lu, % lo, % lx [signed] long [int] 64-2 ^ 63 ~ 2 ^ 63-1% I64dunsigned long [int] 64 0 ~ 2 ^ 64-1% I64u, % I64o, % I64x -- float 32 +/-3.40282e + 038% f, % e, % g -- double 64 +/-1.79769e + 308% lf, % le, % lg % f, % e, % g -- long double 96 +/-1.79769e + 308% Lf, % Le, % Lg: 1. note that each row in the table represents a basic type. "[]" Indicates that it can be omitted. For example, char, signed char, and unsigned char are different types. int, short, and long are also different types. You can use the function overload feature of C ++ for verification, such as void Func (char ch) {} void Func (signed char ch) {} void Func (unsigned char ch) {} is three different functions. 2. The data length of char/signed char/unsigned char is 1 byte. char is signed, but different from signed char. Note that not all compilers do this. The char data length is not necessarily 1 byte, And the char data is not necessarily signed. 3. When char/signed char is converted to int, the maximum sign bit 1 is extended, resulting in operational problems. Therefore, if the data to be processed contains a byte value greater than 127, it is more appropriate to use unsigned char. // At this time, the range is relatively consistent with the integer type. If bit operations are involved in the program, the unsigned variable should also be used. 4. when char/signed char/unsigned char is output, use the format character % c (by character), or use % d, % u, % x/% X, % o, output by integer. % c should be used for input. If the integer is used, Dev-C ++ will give a warning, which is not recommended. 5. The length of the int, whether it is 16-bit or 32-bit, is related to the compiler length. 16-bit compilers (for example, if the compiler used by tcworks is downloaded, The int_16-bit compiler is 32-bit (for example, the compiler cl.exe used by vcss), and The int Is 32-bit. 6. integer data can be input and output in % d, % o, or % x/% X (hexadecimal without symbols. The format character % u indicates unsigned, that is, the hexadecimal mode without symbols. 7. The integer prefix h indicates short, and l indicates long. When the input and output short/unsigned short, we do not recommend that you directly use the int format, such as % d/% u, with the prefix h. This habitual error comes from TC. In TC, the length of the int and the default symbol attributes are consistent with those of short. Therefore, the two types are treated as the same and are Input and Output Using the int method. 8. for long type input and output, "% lld" and "% llu" are the format characters of gcc/g ++ for long int type (64 bits) Input and Output in linux. While "% I64d" and "% I64u" are the format descriptions used in the Microsoft VC ++ library for input and output _ int64 type. The compiler used by Dev-C ++ is Mingw32, and Mingw32 is one of the x86-win32 gcc sub-projects. The core of the compiler is gcc in linux. During the compilation phase, the gcc compiler checks the format string. Obviously, it does not recognize "% I64d ", therefore, the warning "unknown conversion type character 'I' in format" will be given ". Gcc naturally accepts "% lld" and "% llu. Mingw32 uses the gcc Rule Check syntax during compilation, but uses the Microsoft library for connection and runtime. The printf and scanf functions in this library certainly do not know "% lld" and "% llu" under linux gcc, but for "% I64d" and "% I64u ", it is willing to accept and can work normally. 9.% f, % e/% E, or % g/% G can be used for float data input. scanf will automatically process the data according to the input format. You can use % f (normal mode), % e/% E (exponential mode), or % g/% G (automatically selected) for output ). 10. Floating Point parameter pressure stack rules: float (4 bytes) type extended to double (8 bytes) into the stack. Therefore, float (% f) and double (% lf) must be distinguished during input, while % f can be used for output. The printf function outputs the float (extended to double) and double data pushed into the stack according to the double-type rules. If the % lf format character is specified during output, the gcc/mingw32 compiler will give a warning. 11. Dev-C ++ (gcc/mingw32) can select the float length and check whether it is consistent with double. 12. prefix L indicates long (double ). Although long double is 4 bytes longer than double, the value range is the same. The length, precision, and representation range of the long double type are related to the compiler and operating system used.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.