+ 1

i don't understand about prefix and postfix..

4th Jul 2016, 5:26 AM
Rizky lexsi
3 Respuestas
+ 3
see prefix will increament before ending of code but postfix will increament after the code is ended eg) void main() { int a=10,b,c; b=++a; c=a++; cout<<" value of b is"<<b<<endl; cout<<"value of c is"<<c<<endl; cout<<"value of a is"<<a<<endl; } output value of b is11 value of c is11 value of a is12 here the value of b is 11 becoz ++a will increament before ending of semi colon but the value of c remains 11 becoz a++ increament value will reflect after ending of code i.e after the semi colon so the final value of a is 12
5th Jul 2016, 6:25 AM
raju
raju - avatar
+ 1
prefix is first increse then use and postfix is first use then increase
4th Jul 2016, 5:58 AM
Ruchir Gupta
+ 1
About performance, if you dont care which one to use, for example, in a statement like this: x++; You should always use the prefix notation ( ++x ) instead of the postfix ( x++ ) notation because the prefix increments the value and it uses it, while in the postfix notation first a copy of the object is made, then the original value is incremented, then the copy is used and then destroyed.
4th Jul 2016, 3:30 PM
Garme Kain
Garme Kain - avatar