Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What are the assignment rules for different types of c++ values? Urgent! !
What are the assignment rules for different types of c++ values? Urgent! !
C++ is a strongly typed language, and there will be type checking when assigning values, which supports some implicit conversions.

take for example

Char and int can be assigned to each other, because char can be implicitly converted into ASCII code.

Int can be assigned to double, but double can't be assigned to int by default, because there is no precision loss when converting int to double, and implicit conversion is supported, while double to int will lose precision and change the value, so it is necessary to perform forced type conversion to assign a value.

for instance

int I = 10;

Double d = 20

d = I; //Here is actually d = (double) i; Double is implicit and the compiler will complete it automatically.

I = d; //Error, I = (int) d is required; The compiler does not support implicit conversion from double to int, and must perform (int) cast.

There are also type conversions such as custom classes, which need to be checked for operator overloading and the like.