+ 1

x=1 x = ++x ++x; cout<<x<<endl;

The answer is 6.explain me how the answer is 6

6th Nov 2018, 1:03 PM
Suhail Ahmad
Suhail Ahmad - avatar
2 Réponses
+ 12
x = 1 x = ++x + ++x --> 1 = ++1 + ++1 When compiler sees first prefix increment operator 2 = 2 + ++2 When compiler sees the second prefix increment operator 3 = 3 + 3 Now compiler will sum both values and assign it to x 3 = 6 --> x = 6
6th Nov 2018, 7:24 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 5
x = 1; ++x = 2; ++x = 3; x = ++x + ++x; x = 1 + 2 + 3;
6th Nov 2018, 1:19 PM
Izaak GOLDSTEIN
Izaak GOLDSTEIN - avatar