[Solved] How to determine i+++–j in C


Think of it as a greedy algorithm, it will take as many characters as possible, if they make sense.

Example:

i+   // good, keep going
i++  // good, keep going
i+++ // not good, start new token
+    // good, keep going
+-   // not valid, start new token
-    // good
--   // good
--j  // valid

So:

int i = 20;
int j = 5;
int k = i++ + --j; // (20++) + (--5)

That is how it is grouped. The second part is pre and post increment.

i++ // post-increment, use the value first and then increment
--j // pre-increment, decrement first and then use the value

So you get:

int k = 20 + 4
// afterwards: i = 21 and j = 4

1

solved How to determine i+++–j in C