Order of evaluation of expression

前端 未结 6 1008
南旧
南旧 2020-12-11 08:05

I\'ve just read that order of evaluation and precedence of operators are different but related concepts in C++. But I\'m still unclear how those are different but related?.<

6条回答
  •  春和景丽
    2020-12-11 08:48

    Consider the below example:

    #include 
    #include 
    int main(void)
    {
        double a = 1 + UINT_MAX + 1.0;
        double b = 1 + 1.0 + UINT_MAX;
        printf("a=%g\n", a);
        printf("b=%g\n", b);
        return 0;
    }
    

    Here in terms of math as we know it, a and b are to be computed equally and must have the same result. But is that true in the C(++) world? See the program's output.

提交回复
热议问题