0

Please explain me in dummy style

prefix. x=5; y=++x;//x is 6 and y is 6. how suffix. x=5; y=x++;// x is 6 and y is 5. how plis

15th Nov 2016, 8:27 AM
stephen haokip
stephen haokip - avatar
5 Réponses
+ 1
++a is prefix which increases the variables value and the uses the new value in expression. a++ is posfix which takes the variable value first in the expression and then increase the variable. E.g. prefix: int x = 4; int y = ++x; // y = 5 prosfix: int x = 4; int y = x++;// y = 4
15th Nov 2016, 8:30 AM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
0
Do you understand it know or want it even simpler
15th Nov 2016, 8:31 AM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
0
what bout the values of x in both prefix and post fix
15th Nov 2016, 8:39 AM
stephen haokip
stephen haokip - avatar
0
int x = 5; int y = x++; x++ == take the value of 'x' first before executing x. when you get x++ or what ever integer and it has ++ after it then you take the value of the integer before doing the ++ since it comes after the integer. while having it like y = ++x means do the adding first as the ++ comes before the x, the fore you would do 1 + x = 6, therefore y = 6; simplified: ++x do the ++ as it comes first the take that value x++ take the original value of x first then do the ++ therefore: int x =5; int y =x++ //y =5
15th Nov 2016, 8:46 AM
Abdelaziz Abubaker
Abdelaziz Abubaker - avatar
0
With the prefix, the increment operator (++) is executed before the assignment operator(=) and therefore y would be assigned the value of x after it is incremented. With the suffix, the assignment operator is evaluated before the increment operator so therefore y would be assigned the value of x before x is incremented.
15th Nov 2016, 3:56 PM
A-Roy