C++ — type of the division?

前端 未结 6 1440
陌清茗
陌清茗 2021-02-20 02:05

I want to make sure that my understanding of the return type of C++ division,

int / int => return is int?

float / float => return is which type? float?

d         


        
6条回答
  •  一生所求
    2021-02-20 02:56

    Considering only three types (float, double and int):

    • If any of the operand is double, then the result will be double.
    • Else if any of the operand is float, then the result will be float.
    • Else the result will be int .

提交回复
热议问题