+ 1

what is prefix and postfix?

whats their diffrence?

31st Oct 2016, 2:36 PM
Ripon Austin
Ripon Austin - avatar
3 Answers
+ 3
postfix y=x++ means y=x and then x=x+1 prefix y=++x means x=x+1 and then y=x
31st Oct 2016, 3:10 PM
Vipin Kumar
Vipin Kumar - avatar
0
زیزدی
31st Oct 2016, 6:59 PM
Seham Jzبببی
Seham Jzبببی - avatar
0
@Vipin Everything is right, but you can put it alone: int x=1; x++; // x has value 2 x=3; ++x; // x has value 4 it is suggested to use more often prefix, because: int y=5; cout << ++y; //output 6 but: int z=5; cout << z++; //output 5 To clarify - in post incrementation compiler first uses the original value, and then increments, not like in pre incrementation.
1st Nov 2016, 3:51 PM
Wojciech Skibiński
Wojciech Skibiński - avatar