The size of C ++'s main data types in bytes in the computer

Source: Internet
Author: User

I have encountered big-end and small-end problems in data storage. My sister was confused and found that my basic knowledge was seriously lacking, first, let's take a look at how many bytes each data type occupies on your own machine, and the size of these data types is related to Shenma. Various materials are checked, and then code verification is written. In this article, you can add basic knowledge to yourself.

Let's first list the Data Types of C ++:

Integer: int, long. The two are also divided into signed and unsigned. Of course, the size of the signed and unsigned bytes is the same.

Boolean: bool

Character Type: Char, wchar_t

Float, double

This can only be verified by code. It seems that the size of the Data Types of the sub-host is also different. If it is too mighty, I will check my 32-bit Windows computer. The ide I used is code: blocks. I found it quite useful, mainly because the project file is small. It is not as big as creating a project in vs2010. Brother can't afford this hard drive ).

Let's take a look at the integer type. The Code is as follows:

#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;}

Result:

INT: 4

Long: 4

Both int and long occupy 4 bytes (32 bits ).

For other data types, replace the data type in the code above to get the following result:

Bool: 1

CHAR: 1

Wchar_t: 2

Float: 4

Double: 8

Note that the pointer type occupies 4 bytes, because the pointer points to an address and the 32-bit operating system is 4 bytes. Of course, if it is a 64-bit operating system, it is 8 bytes.

In addition, the int type occupies the memory unit size of the operating system. A 16-bit operating system has a memory unit of 64 bits, so it is 2 bytes. A 32-bit system has a memory unit of 32 bits, so it is 4 bytes; A 64-bit operating system memory unit is 16 bits, so it occupies 8 bytes.

 

Because MFC programming is used, there are many data types in MFC. Let's take a look (this is only part of it, there are also many types defined using typedef and macros ).

Bool: int type, Boolean value (true or false)

BSTR: 32-bit character pointer

Byte: an 8-bit integer with no plus or minus signs

Colorref: 32-bit value, representing a color value

DWORD: 32-bit integer with no plus or minus signs

Long: 32-bit integer, positive and negative

Lparam: 32-bit value, which is a parameter of the window function or callback function.

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

Lpstr: 32-bit pointer, pointing to a string

Lpctstr: 32-bit pointer, pointing to a constant string. This string can be transplanted to Unicode

Lptstr: 32-bit pointer, pointing to a string. This string can be transplanted to Unicode

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

Lpresult: 32-bit value, which is returned by the window function or callback function.

Uint: In Win16, 16-bit has no plus or minus signs, and 32-bit has no plus or minus signs in Win32.

Wndproc: 32-bit

Word: A 16-bit integer with no plus or minus signs

Wparam: a parameter of the window function. It is 16 bits in Win16 and 32 bits in Win32.

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.