C + + Basic type learning Notes

Source: Internet
Author: User
Tags constant


The basic types of C + + are divided into two categories: a set of values stored as integers, and a second group consisting of values stored as floating-point formats.

Minimum storage space for C + + arithmetic types
Type + meaning + minimum storage space as follows:

BOOL Boolean type

Char Character type 8 bits

wchar_t Wide-character 16-bit

Short shorter integer 16-bit

int shaping 16 bits

Long plastic 32-bit

Float Single-precision Floating-point type 6 is a valid number

Double double-precision floating-point 10-digit valid number

Long double extended precision floating-point 10-digit valid number

Integral type

Shaping can be divided into: char, short, int, long, long long, each with a signed and unsigned two kinds.
Char is an integer that can represent all the basic symbols in a computer, expressed in one byte. Need to be aware of Cross-border
Short is abbreviated int, long is the abbreviation of long Int.

C + + Cosmetic standards

Short at least 16 digits;
int is at least as long as short;
Long at least 32 bits, and at least as long as int;
A long long of at least 64 digits, and at least the same length as long.

8-bit Char takes a range of 128 ~ 127, unsigned 0 ~ 255
16-bit int takes a value of 32768 ~ +32767, unsigned 0 ~ 65535
The 32-bit int takes a value range of 2147483648 ~ +2147483647, unsigned for 0~4294967295
64-bit int takes a value of 9223372036854775808 ~ +9223372036854775807, unsigned 0 ~ 18446744073709551615

BOOL Type: Literal value true and false can be converted to int type by ascending type, and true is converted to 1,false to 0.

The char type is designed to store characters, such as letters and numbers. C + + pairs characters in single quotes, using double quotes for strings.

Octal 042 is equivalent to decimal cout << Dec;
Decimal cout << Oct;
Hexadecimal 0x42 is equivalent to decimal 66, and the output is 16.
cout << Hex;
cout << 123456 << endl;//1e240

cout << 1492 << Endl;
C + + stores an integer constant as an int unless there is reason to store it as a different type, such as using a special suffix to represent a particular type, or if the value is too large to be stored as int.

Suffix

L or L indicates that the integer is a long constant, and u or u represents the unsigned int constant, and UL (which can be in either order, uppercase or lowercase) represents unsigned long
C++11 provides a suffix ll or ll that represents a long long and also provides a suffix of unsigned long long ull, ull, ull, ull

Const qualifier

When a constant is initialized, its value is fixed and the compiler does not allow the value of the constant to be modified.

Floating point numbers

can represent numbers with a decimal part. Floating point numbers are stored in two parts: part represents a value, and the other part is used to magnify or shrink the value.

3.45E6 refers to the result of multiplying 3.45 and 1000000, E6 represents 10 of 6 times. So 3.45E6 means that 34560000,6 is called an exponent, and 3.45 becomes the mantissa.
A negative index is divided by 10 of the defenses, as 8.55E-4 means 0.000855.
-8.55E4 represents-85500, the preceding symbol is used for numeric values, and the exponent of the symbol user is scaled.

float, double, and long double are described in terms of the number of valid digits they can represent and the minimum range of allowed indices. A valid bit is a meaningful bit in a number.
C and C + + requirements for a valid bit are float at least 32 bits
Double at least 48 digits, and not less than float
Long double minimum and double
Typically float is 32 digits, double is 64 bits, long double is 80 96 or 128 bits, and the other three types have an exponential range of-37 ~ 37

Suffixes are all of the double type by default, and F or f suffixes are available if you want to float. For long double, you can use the L or l suffix.

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.