C++ — type of the division?

前端 未结 6 1446
陌清茗
陌清茗 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 03:13

    The result will be typed (if rule exists) for the assignment. If you have int x = dY + iZ; Then promotion will cause the addition result to be double, but it will be converted to an int when its assigned to x. Google "variable promotion in c++" for more details.

提交回复
热议问题