# Thread: How Does Increment Operators Work...??

1. got it guys got it thX a lot....veeeeee

2. Originally Posted by matsp
That is incorrect. I posted the correct variant in post #3. Note that the third reference to b is "b++", so it takes "b-1" derived from --b, then restores b's value.
I also noted that we can just as well write:
a = 7*b - 4
Well, I was guessing. I didn't know how the actual formula was without the ++ and --.
It was my best guess.

3. Code:
`a = 2*b + (b-1) + 3*(b-1) +b`
So, instead of using --b and b++, I replace them with the value that IS correct for b in each place (assuming we think that 17 _IS_ the correct answer here - since the original expression is technically undefined, there is no "right" or "wrong" answer to that expression - it can be -46, 4118923791231, 17, 14, 19 or some other value with b = 3 to start with).

Then we use normal algebra rules to simplify the expression, soÖ
2 * b + (b -1) can be made into 3 * b - 1.
3 * (b - 1) + b can be made into 4 *b - 3
3 * b - 1 + 4 * b - 3 can be simplified into 7 *b - 4.

Does that make more sense to you. And by the way (appologies if you suffer from some injury or such that), but could you perhaps try to write complete words, correctly spelled (as best as you can) - it is fairly hard for someone who uses English in daily life to read "ne1" as "anyone", etc, and I don't think the people who don't even use english daily will have an EASIER task with it. It makes you look lazy and ill educated - which may be true, but if so, perhaps you can try to hide it when you are posting here

--
Mats

4. Originally Posted by matsp
2 * b + (b -1) can be made into 3 * b - 1.
3 * (b - 1) + b can be made into 4 *b - 3
3 * b - 1 + 4 * b - 3 can be simplified into 7 *b - 4.
I find it easier to simply think and write it as
2b + (b - 1) = 3b - 1
3(b - 1) + b = 3b - 3 + b = 4b - 3
3b - 1 + 4b - 3 = 3b + 4b - 1 - 3 = 7b - 4

Originally Posted by matsp
soÖ
I think you misspelled there too

5. Thanks a lot matsp
you are genious....!!

6. Originally Posted by Elysia
I think you misspelled there too
Using a Swedish keyboard when normally using a US/UK style layout makes them things happen sometimes...

--
Mats

7. Genius? It's basic algebra, something that everyone should be able to use.
I think it is you, my friend, who simply are "ingenious"

Originally Posted by matsp
Using a Swedish keyboard when normally using a US/UK style layout makes them things happen sometimes...

Eh, I say get rid of the UK/US keyboard and use all swedish keyboards! They are far better than US keyboards

8. i ll check on different cases hope it ll work true in all cases

9. As i m new to this so
One day i ll surely fly

10. please tell me for this expresion :
a = (b++) + (- - b) + (b - -) + b
here b = 4
tell me manually ans : i am getting 15
by applying your logic i am gettin 17
plz check.....!!

11. hk_mp5kpdw already answered you in the first reply: it is undefined behaviour. You could get 15, you could get 17, or you could get your computer blown up.

EDIT:
Though I am assuming that you actually fix the statement to become:
Code:
`a = (b++) + (--b) + (b--) + b;`
or at least:
Code:
`a = (b++) + (- - b) + (b--) + b;`

12. Just algebra and...
Stop using -- and ++ in complex operations!

13. plz check this is a different case in 1st case only decrement operators were used in this case both decrement as well as increment operators are used

14. It does not matter.
n++
n--
Is fine.
n + b-- + n++
is not.

15. if the given expression is itself in that form and asked to program on it then how to convert it
if i convert it using algebra i am getting different answers compared to the manual answers so