Basic built-in types

Source: Internet
Author: User

The arithmetic type of C ++: integer, floating point number, single character, and Boolean value. It also defines a special type: void. The storage space of the arithmetic type depends on the machine. The C ++ Standard specifies the minimum storage space for each arithmetic type.

C ++: arithmetic type

Type Description Minimum storage space
Bool Boolean --
Char Character Type 8-digit
Wchar_t Wide character type 16-bit
Short Short integer 16-bit
Int Integer 16-bit
Long Long Integer 32-bit
Float Single precision floating point type 6 is a valid number
Double Dual-precision floating point 10 is a valid number.
Long double Extended precision floating point type 10 is a valid number.

The arithmetic types of integers, characters, and boolean values are collectively referred toInteger.

Character Type: Char and wchar_t. Char is used to store basic characters, usually a single character and its bytes. wchar_t is represented by more than one byte due to the extended character set.

The short type is half-machine word length, while the long type is one or two machine characters long (in 32-bit machines, the int type and long type are usually the same word length ).

The bool type indicates true and false values. Any role of the arithmetic type can be assigned to the bool object. The value 0 indicates false, and any non-0 indicates true.

  1. Signed and unsigned types

Except the bool integer, it can be signed or unsigned ).For unsigned, negative numbers always exceed the value range.However, it is valid to assign a negative number to unsigned. The result isThis negative number evaluates the modulo value of this type.

A point on the Internet about the compiler modulo
This is not transplanted. There is no need to explain and understand.

According to the mathematical model definition, a = B * c + d, B> d> 0 is the modulo. That is to say, the modulo of a negative number is also a positive number, and the modulo of a negative number is a positive number, this actually requires a-B * c> 0. For any a and B, take appropriate c for the equation.

But some programmers always have some strange ideas, such as-1% 2, and want the modulus to be negative, and-1%-2 to be positive, in short, the Division rule is expected to continue to the modulo operation, but if the modulo is set to positive and negative, a-B * c = d will have two solutions, which is more troublesome. Therefore, if your modulo operation has a negative number, you have to doubt whether the modulo is consistent with the definition you want, or you do not need a negative number to participate in the modulo.

Negative number modulo operation: see the http://blog.csdn.net/sonydvd123/article/details/8241666

2.Floating Point Type

The float type is generally represented by a single word (32 is), the double type is represented by two words (64-bit), and the long double type is represented by three or four words (96 or 128.

For actual types, float type precision is usually not enough-float type can only ensure 6 Valid digits, while double type can ensure at least 10 valid digits, it can meet the needs of most computing tasks.

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.