Home > Back-end >  Novice inquired, C n <=2 n or n finally compared with 2? Will have conflict and priority?
Novice inquired, C n <=2 n or n finally compared with 2? Will have conflict and priority?

Time:11-21

In the title
N++ as arithmetic operator precedence is significantly higher than & lt;
=a relational operator
After add parentheses to this subject is (n++) & lt;=2

So according to this view isn't n++ compared with 2?

Run the following program
Int n=0;
While (n++ <=2)
Printf (" % d ", n);

According to my above conclusions should output is 1, 2

But the actual result of the output is 1, 2, 3

That is to say, or n in comparison with 2, why is such result? Not on the higher priority?

CodePudding user response:

N++ is first operation again + +,

CodePudding user response:

N++ & lt;=2 is an expression, n++ is calculated after the value of the expression only since the increasing n, so & lt;=when using n to compare

CodePudding user response:

Is + + n: add 1 after operation;
Add 1 n++ : is first after operation;
  • Related