Why result output is integer even result is defined as float?

后端 未结 4 1403
清酒与你
清酒与你 2021-01-23 01:03
#include

using namespace std;

int main(int argc, char** argv){
        float result;
        result=(340/101);
        cout<<\"Result=\"<

        
4条回答
  •  鱼传尺愫
    2021-01-23 02:05

    Because the expression (340/101) is evaluated independent of its surrounding context. int/int always results in an int. It makes no difference if you store that int in a float variable later on.

提交回复
热议问题