Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 views
in Technique[技术] by (71.8m points)

sequence point concept in java

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...