Originally posted by Enzo Del Mistro:
I calculate it with the following precedence:
(3) + ((1)) + 3 = 7
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
int k = 1;
int i = ++k + k++ + + k;
System.out.println(i);
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Sri Sri:
I am assuming something here that
int i = ++k + k++ + ++k;
(3) now calculate ++k, as we have not encountered the end of statement , after step (2) k remains 2.
Originally posted by Enzo Del Mistro:
Thanks for the information. The expression is how I stated though:
int z = ++k + k++ + + k;
I also understand the left to right rule you mentioned. The question I have is that the documentation of precendence I have states that postfix has the same precedence as () which is higher than prefix, therefore I would suspect that k++ should be executed first? Therefore rendering 3 + 1 + 3. Is that valid reasoning?
May the force of the Java be in all of us !!!
Originally posted by Layne Lund:
I know for sure that this kind of statement has undefined results in C++. Now I'm curious about the Java specification. I am willing to bet it is similar.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|