I would like it if someone can check my answer on this...
Question: How many possible values are there for the expression (i++) + (i--)? What are the values, assuming that i has the value 1 initially?
So, i =1
I know that the postfix operators can be tricky because we don't know if the compiler will perform the operation immediately, or later.
I think that there are 3 possible values for this expression
first, can be calculated with both sets of post fix operators performed at the same time
second, can be calculated with the first set operator performed, while the second set is not.
third, can be calculated with the first set not being performed yet, while the second set is.
I don't think that there is a solution in which neither of the sets of post fix operators are performed because the compiler must perform before moving to the next line.
Thus, I think the possible answers are 2, 3, 1
i=1
(i++) + (i--) also (2) + (0) =2
(i++) + (i--) also (2) + (1) = 3
(i++) + (i--) also (1) + (0) = 1
Am I correct?
Question: How many possible values are there for the expression (i++) + (i--)? What are the values, assuming that i has the value 1 initially?
So, i =1
I know that the postfix operators can be tricky because we don't know if the compiler will perform the operation immediately, or later.
I think that there are 3 possible values for this expression
first, can be calculated with both sets of post fix operators performed at the same time
second, can be calculated with the first set operator performed, while the second set is not.
third, can be calculated with the first set not being performed yet, while the second set is.
I don't think that there is a solution in which neither of the sets of post fix operators are performed because the compiler must perform before moving to the next line.
Thus, I think the possible answers are 2, 3, 1
i=1
(i++) + (i--) also (2) + (0) =2
(i++) + (i--) also (2) + (1) = 3
(i++) + (i--) also (1) + (0) = 1
Am I correct?