Char,short, int, Long,long long,unsigned long Long data range

Source: Internet
Author: User

Quick Check Table:

char-128 ~ +127 (1 bytes)
short-32767 ~ + 32768 (2 Bytes)
unsigned short 0 ~ 65535 (2 Bytes)
int-2147483648 ~ +2147483647 (4 Bytes)
unsigned int 0 ~ 4294967295 (4 Bytes)
Long = = Int
Long long-9223372036854775808 ~ +9223372036854775807 (8 Bytes)
Double 1.7 * 10^308 (8 Bytes)

unsigned int 0~4294967295
The maximum value of long long: 9223372036854775807
The minimum value of long long:-9223372036854775808
Unsigned the maximum value of long long: 18446744073709551615

Maximum value of __int64:9223372036854775807
Minimum value of __int64:9223372036854775808
Maximum value of unsigned __int64:18446744073709551615

Detailed Tutorials:

====================

Symbol attribute length attribute basic type number of placeholder value range Input Example output character example
----Char 8-2^7 ~ 2^7-1%c%c,%d,%u
Signed--Char 8-2^7 ~ 2^7-1%c%c,%d,%u
Unsigned--Char 8 0 ~ 2^8-1%c%c,%d,%u
[Signed] short [int] 16-2^15 ~ 2^15-1%HD
unsigned short [int] 0 ~ 2^16-1%hu,%ho,%HX
[Signed]--int 32-2^31 ~ 2^31-1%d
unsigned--[int] 0 ~ 2^32-1%u,%o,%x
[Signed] long [int] 32-2^31 ~ 2^31-1%ld
unsigned long [int] 0 ~ 2^32-1%lu,%lo,%LX
[Signed] long long [int] 64-2^63 ~ 2^63-1%i64d
unsigned long long [int] 0 ~ 2^64-1%i64u,%i64o,%i64x
----float +/-3.40282e+038%f,%e,%g
----double +/-1.79769e+308%lf,%le,%lg%f,%e,%g
--long double + +/-1.79769e+308%lf,%le,%LG

A few notes:

1. Attention! Each row in the table represents a basic type. The "[]" representation can be omitted.
For example: Char, signed char, unsigned char are three distinct types;
int, short, and long are also three different types.

2. char/signed char/unsigned char type data length is 1 bytes;
Char is a signed type, but is different from signed Char.
Attention! Not all compilers do this, and char data length is not necessarily 1 bytes, and char is not necessarily a signed type.

3. When converting char/signed char to int, the highest sign bit 1 is extended, resulting in computational problems.
Therefore, it is more appropriate to use unsigned char if there is a case where the byte value is greater than 127 in the data being processed.
If a bit operation is involved in a program, the unsigned variable should also be used.

4. char/signed char/unsigned char output, use the format character%c (by character), or use%d,%u,%x/%x,%o, output by integer, and when input, use%c, if using integer, dev-c++ will give Warning, it is not recommended to use this.

5. The length of int is 16-bit or 32-bit, which is related to the compiler word size.
16-bit compilers (such as the compiler used by TC), int is 16-bit, and 32-bit compiler (such as VC used by compiler Cl.exe), int is 32 bits.

6. Integer data can use%d (signed 10 binary),%o (unsigned 8 binary) or%x/%x (unsigned 16 binary) input output. The format character,%u, represents unsigned, which is the unsigned 10 binary method.

7. Integer prefix h denotes short, l indicates long.
When input and output short/unsigned short, it is not recommended to use the format character%d/%u of int directly, etc., prefix h. This customary error comes from the TC. TC, the length of the int and the default symbol properties, are consistent with the short, so that the two types are the same, both the input and output in int way.

8. For a long long type of input and output:
"%lld" and "%llu" are the format characters used by Linux under gcc/g++ for a long long int type ("bits") input output.
"%i64d" and "%i64u" are the format descriptions used for input and output __int64 types in the Microsoft VC + + library.

The compiler used by dev-c++ is Mingw32, Mingw32 is one of the X86-win32 gcc sub-projects, the compiler core or GCC under Linux.
The function parameter type check is in the compile phase, the GCC compiler checks the format string, obviously it does not recognize "%i64d",
So the warning "unknown conversion type character ' I ' in format" will be given. For "%lld" and "%llu", GCC took it for granted.

MINGW32 uses GCC rules to check the syntax during compilation, but it uses the Microsoft library when connecting and running.
The printf and scanf functions in this library are of course not aware of Linux gcc under "%lld" and "%llu", but for "%i64d" and "%i64u", it is willing to accept, and can work properly.

9. Floating-point data input can be used%f,%e/%e or%g/%g, scanf will be automatically processed according to the input data form.
You can use%f (normal),%e/%e (exponential), or%g/%g (auto-Select) for output.

10. Rules for floating-point parameter compaction: the Float (4-byte) type expands into a double (8-byte) stack.
So when entering, you need to distinguish between float (%f) and double (%LF), and in the output, use%f.
The printf function will output the float (which has been expanded to double) and double type data pressed into the stack according to the rules of type double.
If you specify the%LF format character at output, the Gcc/mingw32 compiler will give you a warning.

Dev-c++ (GCC/MINGW32) can choose the length of float, whether it is consistent with double.

12. The prefix L represents a long (double).
Although a long double is 4 bytes longer than a double, the range of values represented is the same.
The length, precision, and representation range of a long double type are related to the compiler, operating system, and so on.

Char,short, int, Long,long long,unsigned long Long data range

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.