It's my first post and I know similar things were posted.... but i got a problem understanding something. I know the difference with ++i and i++
- ++i first increments the 'i' then return value of 'i'
- i++ increments 'i' and returns value before it was incremented
I got a question on Job interview: "What will be the value of i"
int test(){
int i = 0;
try {
return i++;
} finally {
return ++i;
}
}
According to what i wrote above, i thought it should be 1. But after checking it in some test app i know its 2. So my Question is: Why?
When i played with it a little and switched ++i with i++
int test(){
int i = 0;
try {
return ++i;
} finally {
return i++;
}
}
In this case value of i is as expected 1. So why is that?