Implicit type conversions

Source: Internet
Author: User

1. In a mixed-type arithmetic expression: the widest data type becomes the target conversion type. "Also called arithmetic conversions."
int ival = 3;
Double dval = 3.14159;
Ival is promoted to double type 3.0
Ival+dval;
2. Assign one type of expression to an object of another type int *pi = 0; Constant integer 0 null pointer value converted to INT * type
Ival = Dval; Dval is truncated to an int value of 3

3. Passing an expression to a function, the type of the invocation expression is not the same as the type of the formal parameter extern double sqrt (double);
COUT&LT;&LT;SQRT (2) <<endl; 2 is promoted to a double type.

4. Returns an expression from a function with a different type than the return type double difference (int ival1, int ival2)
{return ival1-ival2; The return value is promoted to double type
}
Basic principles of arithmetic conversion:
1, in order to prevent the loss of precision, if necessary, the type is always promoted to a wider type.
2. All arithmetic expressions of an ordered type with less than integral type will be converted to integers before they are evaluated.





























From for notes (Wiz)

Implicit type conversions

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.