+ 1

What is the output of i=++i + ++i in C , provided the initial value of i is 2?

13th Sep 2019, 4:05 PM
SWETA X
SWETA X - avatar
5 Réponses
+ 2
Even if the variable is the same? I mean, in an expression like ++i + ++j we don't know if i is incremented before j, but in ++i + ++i the final value shouldn't depend on the order of incrementation.
14th Sep 2019, 5:42 AM
AndreaC
AndreaC - avatar
+ 1
8 because you pre-increment i twice.
13th Sep 2019, 4:39 PM
AndreaC
AndreaC - avatar
+ 1
AndreaC can you please elaborate the process?
13th Sep 2019, 4:42 PM
SWETA X
SWETA X - avatar
+ 1
You start with i=2, after the first pre-increment you have i=3, after the second one i=4, finaly the addition.
13th Sep 2019, 4:55 PM
AndreaC
AndreaC - avatar
+ 1
I see, I didn't consider the possibility of two different copies of i, thank you 🙂
14th Sep 2019, 7:02 AM
AndreaC
AndreaC - avatar