V
Vasu
Hi !
Following is the snippet of question / answer on Sun Java site of Java
tutorial :
Consider the following code snippet:
int i = 10;
int n = i++%5;
Question: What are the values of i and n after the code is executed?
Answer: i is 11, and n is 0.
Question: What are the final values of i and n if instead of using the
postfix increment operator (i++), you use the prefix version (++i))?
Answer: i is 11, and n is 1.
My question is : in the first answer they have said n is 0, now if we
go by code execution system from top to bottom and left to right, when
compiler hits % operator i has already become 11 (10 + 1 = 11) and
dividing it with 5 we will get 1 remainder, but there answer says n is
0 - why? It should be same as they have shown in answer of 2nd
question.
Can anybody respond to my query.
Thanks in advance.
Vasu
Following is the snippet of question / answer on Sun Java site of Java
tutorial :
Consider the following code snippet:
int i = 10;
int n = i++%5;
Question: What are the values of i and n after the code is executed?
Answer: i is 11, and n is 0.
Question: What are the final values of i and n if instead of using the
postfix increment operator (i++), you use the prefix version (++i))?
Answer: i is 11, and n is 1.
My question is : in the first answer they have said n is 0, now if we
go by code execution system from top to bottom and left to right, when
compiler hits % operator i has already become 11 (10 + 1 = 11) and
dividing it with 5 we will get 1 remainder, but there answer says n is
0 - why? It should be same as they have shown in answer of 2nd
question.
Can anybody respond to my query.
Thanks in advance.
Vasu