C + + Implicit type conversion

Source: Internet
Author: User

C + + defines the conversion criteria between a set of built-in type objects, which are implicitly converted by the compiler when necessary

1. In the arithmetic expression of mixed operation, the widest data type becomes the target conversion type

2. When assigning values between different types of expressions, the object type being assigned becomes the target conversion type

3. When the function call argument is inconsistent with the parameter type, the object type of the formal parameter becomes the target conversion type

4. When the function's return value type is different from the type of the function expression, the type of the function expression becomes the target conversion type

Note: Two common guidelines for arithmetic operations are as follows

(1) In order to prevent the loss of precision, the type is always promoted to a wider type.

(2) All arithmetic expressions with ordered types that contain less than integers are converted to integer (that is, integer promotion) before they are evaluated and then converted to the defined type.

C + + Implicit type conversion

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.