I am new to Java and have background of C.I am going through Khalid Moughal's book. On page 126 he gives an example as
int i = 10;
int k = ++i + --i; // ((++i) + (--i)).
This clearly violates the sequence point concept as of C,which says that you can't change the value of a variable more than once with in same sequence point. My question is does the same sequence point rule applies in java or not? It may be that he has taken this example just to explain the concept of prefix unary operator and it's side effect but such an example which clearly violates a very fundamental rule of the language is not expected in a book as renowned as Khalid Moughal.
So please confirm it.
Hope you people take it into proper spirit.
Thanks,
Mawia
My question is does the same sequence point rule applies in java or not?
No, there are no sequence-points in Java. Order of evaluation (etc) is well defined in Java.
Also read this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With