The relation and application of int,unsigned int, short in C + +

Source: Internet
Author: User

The type of int is special, and the specific number of bytes is related to the machine word length and compiler. If you want to ensure the portability, try to use __int16 __int32 __int64.
__int16, __int32 This data type allocates the same bytes under all platforms. So there's no problem with the transplant.
The so-called non-portability refers to: when code written on one platform cannot be run on another platform, the desired running result cannot be achieved.
For example: on the 32 platform (so-called 32-bit platform refers to the universal register data width is 32) to write code, the int type is assigned 4 bytes, and the 16-bit platform is the allocation of 2 bytes, then on the 16-bit compiled EXE,
Which is to allocate 2 bytes for int, while running on 32-bit platform, it will be parsed according to 4 bytes, obviously will be wrong!!

For non-int rows, so far, all types of bytes allocated are compatible, that is, different platforms allocate the same number of bytes for the same type!!

Recommendation: Try to avoid using the int type in your code, and substitute short,long,unsigned int for different needs.

Here are the various types of list "Go"

64-bit refers to the data width of the CPU general register is 64 bits.

Data type name Number of bytes Alias Range of values
Int * signed,signed int Determined by the operating system , which is related to the "word length" of the operating system
unsigned int * Unsigned Determined by the operating system, which is related to the "word length" of the operating system
__int8 1 char,signed Char –128 to 127
__int16 2 Short,short int,signed Short int –32,768 to 32,767
__int32 4 signed,signed int –2,147,483,648 to 2,147,483,647
__int64 8 No –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
bool 1 No False or True
Char 1 Signed Char –128 to 127
unsigned char 1 No 0 to 255
Short 2 Short int,signed Short int –32,768 to 32,767
unsigned short 2 unsigned short int 0 to 65,535
Long 4 Long int,signed Long int –2,147,483,648 to 2,147,483,647
Long Long 8 None (but equivalent to __int64) –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
unsigned long 4 unsigned long int 0 to 4,294,967,295
Enum * No Determined by the operating system, which is related to the "word length" of the operating system
Float 4 No 3.4E +/-(7 digits)
Double 8 No 1.7E +/-308 (digits)
Long double 8 No 1.7E +/-308 (digits)
wchar_t 2 __wchar_t 0 to 65,535

Type identifier Type description Length
bytes
Range Note
Char Character type 1 -128 ~ 127 -27 ~ (27-1)
unsigned char No character type 1 0 ~ 255 0 ~ (28-1)
Short int Short-integer 2 -32768 ~ 32767 2-15 ~ (215-1)
unsigned short int No character short integer type 2 0 ~ 65535 0 ~ (216-1)
Int Integral type 4 -2147483648 ~ 2147483647 -231 ~ (231-1)
unsigned int No-character integer 4 0 ~ 4294967295 0 ~ (232-1)
Float Real type (single precision) 4 1.18*10-38 ~ 3.40*1038 7-bit significant bit
Double Real type (double precision) 8 2.23*10-308 ~ 1.79*10308 15-bit significant bit
Long double Real type (long double precision) 10 3.37*10-4932 ~ 1.18*104932 19-bit significant bit

The relation and application of int,unsigned int, short in C + +

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.