is it possible | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

is it possible

x = 5; y = ++x++; // x is 6, y is 7

2nd Jan 2018, 1:48 PM
Parth N. Prajapati
Parth N. Prajapati - avatar
2 Antworten
+ 4
int y = ++x++; // is equivalent to int y = ++(x++); // evaluates to int y = ++(5); and ++5 is not possible The operand of an increment or decrement operator must be a variable, and here it is a constant so it is not possible
2nd Jan 2018, 1:56 PM
GAWEN STEASY
GAWEN STEASY - avatar
0
As a tip, to get your above statement to work, you may add brackets like this: int y = (++x)++; This works as ++x is still an lvalue while x++ is a rvalue. Since you can only perform increment on an lvalue and not on an rvalue, this works. For details on why ++x is an lvalue and x++ isn't, visit this: https://stackoverflow.com/questions/371503/why-is-i-considered-an-l-value-but-i-is-not
2nd Jan 2018, 2:36 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar