Can anyone explain me what is postfix and prefix? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can anyone explain me what is postfix and prefix?

Guys, I still haven't understood what postfix and prefix is, can anyone help? For example int x = 1; int y = ++x; //What's this? int x1 = 1; int y1 = x1++; // And this? Thanks

12th Jul 2017, 10:33 PM
Taxyd Tails
Taxyd Tails - avatar
3 Answers
+ 1
int x = 1; int y = ++x // increments x then stores it. x = 2, y = 2 x = 1 int z = x++ // stores x then increments. x = 2, z = 1
12th Jul 2017, 10:58 PM
Andrew Lampert
Andrew Lampert - avatar
0
int x = 1; int y = ++x; // Prefix calcola il valore di x, e poi assegna il suo valore ad y. In questo caso x e y saranno uguali. int x1 = 1; int y1 = x1++; // Postfix assegna il valore di x a y, dopo calcola il valore di x. I questo caso y e x saranno diversi, perchè prima y = x, poi x viene modificato aggiungendogli 1.
16th Dec 2017, 5:30 AM
CuriousCI
CuriousCI - avatar
0
sadly, i dont know.
27th Mar 2019, 4:57 PM
Floofy