The byte size of the C + + primary data type in the computer

Source: Internet
Author: User

Met the big end of data storage and small-ended problems, this your sister's confused, found that I have a serious lack of basic knowledge, ah, first understand the C + + data types on their own machine accounted for how many bytes, and these data types accounted for the size of the bytes of God and horse. All kinds of check data and then write code test, summarized in this article, to fill their basic knowledge.

Let's start by listing the data types of C + +:

Integral type: Int,long. These two also divide signed (signed) and unsigned (unsigned), of course, signed and unsigned the size of the byte is the same, regardless of him.

Boolean type: BOOL

Character Type: char,wchar_t

Floating point type: float,double

This can only be on the code verification, seemingly different data types of the machine accounted for different sizes, too powerful, I will check my 32-bit Windows system computer. I use the IDE is code::blocks, found very useful, mainly engineering documents small, not like VS2010 built a project is very big, brother this small hard disk is unbearable AH (off-topic).

First look at the whole type of bar, the code is as follows:

1234567891011121314 #include <iostream>using namespace std;int main(){    int a;    long b;    int Byteof_int=sizeof(a);    int Byteof_long=sizeof(b);    cout << "int:" <<Byteof_int<<endl;    cout << "long:" <<Byteof_long<<endl;    return 0;}

The results show:



Both int and long are 4 bytes (that is, 32 bits).

Other data type validation bar the above code data type is replaced by, the following results are obtained:






It is particularly important to note that for pointer types, it is 4 bytes because the pointer is pointing to an address and the 32-bit operating system is 4 bytes. Of course, if it's a 64-bit operating system, that's 8 bytes.

In addition, this type of int accounts for one memory unit size of the operating system. Previous 16-bit operating system a memory unit is 64 bits, so it is 2 bytes, 32 bit system a memory unit is 32 bits, so 4 bytes; 64-bit operating system a memory unit is 16 bits, so it accounts for 8 bytes.

Because MFC programming, MFC has a lot of data types Ah, see (This is only part, there are a lot of typedef and macro-defined types).

Type Bool:int, Boolean value (TRUE or FALSE)

Bstr:32-bit character Pointer

Byte:8-bit Integer, no sign

Colorref:32-bit value, which represents a color value

Dword:32-bit Integer, no sign

Long:32-bit integer with positive and negative number

Lparam:32-bit value, as a parameter of a window function or callback function

Lpcstr:32-bit pointer, pointing to a constant string

Lpstr:32-bit pointer, pointing to a string

The lpctstr:32-bit pointer, pointing to a constant string. This string can be ported to Unicode

The lptstr:32-bit pointer, pointing to a string. This string can be ported to Unicode

Lpvoid:32-bit pointer, pointing to an unspecified type of data

Lpresult:32-bit value, as a return to a window function or callback function

Uint:win16, 16-bit no sign, Win32, 32-bit no sign


Word:16-bit Integer, no sign

WPARAM: A parameter of the window function, Win16 in 16bits,win32 32bits

The byte size of the C + + primary data type in the computer

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: 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.