C ++ expression-type conversion

Source: Internet
Author: User

Implicit type conversion
1. In mixed arithmetic operations, the widest type is the target conversion type.
Int x = 2.32 + 2; // 2 is upgraded to double
2. In the value assignment operation, the assigned object is of the target conversion type.
Int x = 2.32 + 2 // 2 is upgraded to the double type, and then converted to the int type after the double type is added to the 4.32 double type. The value is assigned to X. please remove the decimal places directly.
3. In function call Parameters
Double SQRT (double); SQRT (2); // converts 2 to double
4. the return value of the function call is
Double SQRT (double)
{
Return 2; // 2 is converted to double type
}

Arithmetic Conversion
1. To prevent loss of precision, the type is always converted to a wider type.
2. All sorted sequence expressions smaller than the integer type are converted to the integer type before calculation.
Char cval;
Bool found;
Enum mumble {M1, M2, M3} mval;
Unsigned long ulong;
Char C1 = 'A', C2 = 'B ';

Cval + ulong; // it can be considered that cval is converted to the int type before calculation.
Sizeof (C1 + C2); // converts both C1 and C2 to int type.

Unsigned int is wider than Int.
Some exceptions, such as long and unsinged int, will be converted to unsigned long (32-bit operating system)

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.