C + + Essentials (1): Basic built-in type

Source: Internet
Author: User

Mastering a variety of basic types is a prerequisite for proper processing of various data in programming, where data is stored and transmitted in bits (bit), and each 8 bits is composed of 1 bytes (byte). The word length of a 32-bit computer is 32, or 4 bytes, and the corresponding 64-bit computer has a word length of 64, or 8 bytes.

The bool has a length of 1 bytes, or 8 bits.

Char has a length of 1 bytes, while C + + is unique to a wchar_t of 2 bytes, or 16 bits.

int is usually 1 word length, short is half word length, long is 1 or 2 word length.

? Float is a length of one word, a double is two word lengths, and a long double is 3 or 4 word lengths.

The length of the memory that the pointer occupies is also determined by the system, which is 32 bits under the 32-bit system and 64 bits under the 64-bit system.

Run the following code according to Win32 conditions:

#include <iostream>using namespace Std;int main () {cout << "bool:" << sizeof (BOOL) << endl;cout &L t;< "char:" << sizeof (char) << endl;cout << "wchar_t:" << sizeof (wchar_t) << endl;cout &L  t;< "short:" << sizeof (short) << endl;cout << "int:" << sizeof (int) << endl;cout << "Long:" << sizeof (long) << endl;cout << "float:" << sizeof (float) << endl;cout << "do Uble: "<< sizeof (double) << endl;cout <<" pointer: "<< sizeof (char*) << Endl;return 0;}

The result of the operation is as follows (sizeof returns the number of bytes):

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.