+ 1
Prefix and postfix in C# (I really need help 😢)
num = 3 ; num = num *num /++num ; Console.Write(num); I am really confused with this question why Is the final answer for num equals 2 not 4 ?? As a prefix ++num is solved first and it is the same as num = num +1 and this means that num is now 4 but when he went to solve num * num he used num equals to 3 not 4 !!
2 odpowiedzi
+ 1
Both prefix and postfix increment starts increase from itself, that is:
num = 3
(1) (2) (3)
num + num++ + num
(1) (2) (3)
num + ++num + num
Both num at (1) is 3.
Both num at (3) is 4.
But num++ at (2) is 3,
while ++num at (2) is 4.
(1) (2) (3)
So num * num / ++num
In (1) and (2) num is 3, in (3) num is 4.
3*3/4 = 9/4 = 2.
+ 1
Thanks alot 🌸you really made it clear .