+ 2

Simple and funny puzzle.

Hey guys and girls. First of all,before you'll post your answer be sure it have answer on each item here: 1.What's sum values on each step? 2.What's i value on each step? 3.How exectly increments and decrements works on each step? 4.X = ? i = 1; x = 0; x = i++ + i++ + ++i + i++ + --i + ++i; Good luck!

15th May 2017, 5:12 AM
Rose Sevenyears
Rose  Sevenyears - avatar
5 ответов
+ 9
from left to rigt, at each addition step of expression; x = i++; // <=> x += 1 (x == 1) // x += (i == 1); (i += 1) == 2; x += i++; // <=> x += 2 (x == 3) // x += (i == 2); (i += 1) == 3 x += ++i; // <=> x += 4 (x == 7) // (i += 1) == 4; x += (i == 4) x += i++; // <=> x += 4 (x == 11) // x += (i == 4); (i += 1) == 5 x += --i; // <=> x += 4 (x = 15) // (i -= 1) == 4; x += (i == 4) x += ++i; // <=> x += 5 (x = 20) // (i += 1) == 5; x += (i == 5) x == 1+2+4+4+4+5 == 20
15th May 2017, 3:43 AM
visph
visph - avatar
+ 18
x=1+2+4+4+4+5=20
14th May 2017, 10:14 PM
Tashi N
Tashi N - avatar
+ 10
@Yaroslav: :) lol. nothing like a little bit of increment operator abuse to hurt ones brain
14th May 2017, 10:46 PM
jay
jay - avatar
+ 5
Yep, that's all about abusing increments , but helps at undestanding how it works soooooo much :) Good Job :) It broke my brain once again even if I solved it like mounth ago , so I posted it for others :D Visps's answer had most info , so his answer will be best I guess , he deserves it :)
15th May 2017, 4:53 AM
Rose Sevenyears
Rose  Sevenyears - avatar
+ 3
hate this puzzles. especially at 1AM
14th May 2017, 10:29 PM
Yaroslav Pieskov
Yaroslav Pieskov - avatar