The nature of operators and priority calculation

When autumn comes on September 8th, my flowers will bloom

There are three influencing factors that affect the evaluation of expressions:
1. The precedence of operators
2. The associativity of operators
3. Whether to control the order of evaluation.
So when we calculate complex expressions, we must clarify the nature and nature of each operator priority.

Classification (dendrogram)

Insert picture description here

Detailed form

Priority decreases
Insert picture description here
Insert picture description here

Priority calculation problem

We understand that after learning the priority of operators, there are simple calculation paths for some complex expressions, but some problems also arise, such as:
a b + c d + e f
How to calculate the above expression? ?
It is possible
a
b
c d
a
b + c d
e
f
a b + c d + e f It
is also possible
a
b
c d
e
f
a b + c d
a b + c d + e*f

So how to determine the calculation path?
Let's test it with a bunch of codes:

int main()
{
    
    
 int i = 10;
 i = i-- - --i * ( i = -3 ) * i++ + ++i;
 printf("i = %d\n", i);
 return 0; 
 }

There are different results under different compilers:
Insert picture description here

It shows that the calculation path cannot be determined by the compiler itself.
Summary:
If the expression of the program we write cannot determine the unique calculation path through the attributes of the operator, then this expression is problematic.

Guess you like

Origin blog.csdn.net/qq_40893595/article/details/104320367