Implicit type conversion rules in C++ operators

后端 未结 9 2097
情书的邮戳
情书的邮戳 2020-11-22 00:21

I want to be better about knowing when I should cast. What are the implicit type conversion rules in C++ when adding, multiplying, etc. For example,

int + fl         


        
9条回答
  •  情深已故
    2020-11-22 00:24

    Caveat!

    The conversions occur from left to right.

    Try this:

    int i = 3, j = 2;
    double k = 33;
    cout << k * j / i << endl; // prints 22
    cout << j / i * k << endl; // prints 0
    

提交回复
热议问题