Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...