prefix increment in cpp | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

prefix increment in cpp

Hallo, citizens! Why result of compiling this code: int x = 10, y; y = x + ++x + ++x; cout << x << " "<<y; in vs2010 - 36; in all of online compilers - 34? And what result correct? Thanks.

28th Mar 2017, 6:05 AM
Eldar Rivin
Eldar Rivin - avatar
2 Réponses
0
The result of the calculation is 36 because prefix incrementation is performed before getting the value of x.
28th Mar 2017, 8:45 AM
Sven Dhuva
Sven Dhuva - avatar
0
I guess, in this app result is 34, because it uses a specific compiler. Is there any manual about this?
28th Mar 2017, 1:04 PM
Eldar Rivin
Eldar Rivin - avatar