RPM: The number of bytes in a C + + base data type

Source: Internet
Author: User

Reference: http://blog.csdn.net/vast_sea/article/details/8076934

On this basic question, it is clear from a long time ago that the C standard does not specify the number of bytes that the basic type should be, and this is also related to the machine, OS, compiler, such as the 32bits operating system, VC + + compiler under the int type is accounted for 4 bytes , while the TUBORC is 2 bytes.

Therefore, the width of the int,long int,short int may vary depending on the compiler. But there are several ironclad principles (Ansi/iso):

    • sizeof (short int) <=sizeof (int)

    • sizeof (int) <=sizeof (long int)

    • Short int should be at least 16 bits (2 bytes)

    • A long int should be at least 32 bits.

The following gives the number of bytes for the base data type under the different bits compiler:



16-bit compilers


Char:1 bytes
char* (i.e. pointer variable): 2 bytes
Short Int:2 bytes
Int:2 bytes
Unsigned int:2 bytes
Float:4 bytes
Double:8 bytes
Long:4 bytes
A long long:8 bytes
Unsigned long:4 bytes


32-bit compilers


Char:1 bytes
char* (i.e. pointer variable): 4 bytes (32-bit addressing space is 2^32, which is 32 bit, or 4 bytes. Similarly 64-bit compilers)
Short Int:2 bytes
Int:4 bytes
Unsigned int:4 bytes
Float:4 bytes
Double:8 bytes
Long:4 bytes
A long long:8 bytes
Unsigned long:4 bytes


64-bit compilers

Char:1 bytes
char* (i.e. pointer variable): 8 bytes
Short Int:2 bytes
Int:4 bytes
Unsigned int:4 bytes
Float:4 bytes
Double:8 bytes
Long:8 bytes
A long long:8 bytes
Unsigned long:8 bytes

The following references: http://blog.csdn.net/vast_sea/article/details/8076897

Machine Word length: Refers to the number of bits of binary data that a computer can handle in an integer operation (integer operation is a fixed-point integer operation). The machine word length is the length of the fixed-point arithmetic, usually the width of the internal data path of the CPU. It is now generally 32 bits, which is 4 bytes, and also 64-bit and 16-bit.

The arithmetic type of storage space is determined by the machine. In general, the short type is half machine word length, int is a machine word length, long is 1 or 2 machine word length, float is a machine length, double is two characters, long double is 3 or 4 words. The C + + standard specifies the minimum storage space for each arithmetic type, but it does not prevent the compiler from having larger storage space. If you want to ensure portability, try to use __int16 __int32 __int64 bar, or your own typedef int INT32 a bit.

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

(P: The size of the pointer is a fixed value of 4 bytes)

RPM: The number of bytes in a C + + base data type

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.