我想知道什么时候应该投出更好.在添加,乘法等时,C++中的隐式类型转换规则是什么.例如,
int + float = ?
int * float = ?
float * int = ?
int / float = ?
float / int = ?
int / int = ?
int ^ float = ?
Run Code Online (Sandbox Code Playgroud)
等等...
表达式是否总是被评估为更精确的类型?Java的规则有所不同吗?如果我不准确地说出这个问题,请纠正我.
C#中的程序:
short a, b;
a = 10;
b = 10;
a = a + b; // Error : Cannot implicitly convert type 'int' to 'short'.
// we can also write this code by using Arithmetic Assignment Operator as given below
a += b; // But this is running successfully, why?
Console.Write(a);
Run Code Online (Sandbox Code Playgroud)