switch statement and incrementation
c
Solution
Since the value of i does not change, the value of j doesn't either.
Not true.
`j += i` is the same as `j = j + i`, and `i is 2` once inside the `switch(..)` statement.
This executed 3 times gives you `6`.
Problem
I have the following code: ``` int i = 1; int j = 0; switch (i++) { case 1: j += i; case 2: j += i; case 3: j += i; break; } printf("%d %d",i, j); ``` The `i++` expression evaluates `i` to 1 since it's a post-increment operator, so the statements in case 1 will be executed, which means `j` is evaluated to 2. Then without breaks, the program continues to execute all the following statements. Since the value of `i` does not change, the value of `j` doesn't either. So I expect the output to be something like `2 2` but it turned out to be `2 6`. Can anyone give me an explanation please, thanks!