confused with operators ++ --

Pages: 12
closed account (o3hC5Di1)
Thanks Disch for your elaborate explanation - helped me understand the issue too.

All the best,

NwN
--a*b(original value)/b(original value): 5/5
That 2nd 'b' may or may not be the original value. It may be the incremented value. This behavior is not defined by the C++ standard and you must never do this in actual code.

@disch i have one more question. how should it be done if i want the 2nd 'b' to keep the original value ?

thanks again for the help.
Just split it on more lines
1
2
c=--a*b/b;
++b;


It's probably a good idea to always avoid side effects in the expressions to be honest. Trying to do everything in one line is often bad for readability. Much easier to follow:
1
2
3
--a;
c=a*b/b;
++b;
Last edited on
thanks you very much :)
Topic archived. No new replies allowed.
Pages: 12