c# - Incrementing and decreasing i is not working properly -
the following 2 lines of code not returning same value. reason that?
int i; = 1; = + i++; //returns 2, expecting 3
and
i = 1; = i++ + i; //returns 3
semantically, should same a + b = b + a
right?
the same decreasing i
:
i = 1; = - i--; //returns 0, expecting 1
and
i = 1; = i-- - i; //returns 1, expecting -1
what confuses me more usage of post increment operators:
i = 1; = + ++i; //returns 3
and
i = 1; = ++i + i; //returns 4, expecting 3
same again decreasing operator:
i = 1; = - --i; //returns 1
and
i = 1; = --i - i; //returns 0, expecting -1
last question:
how these 2 lines interpreted compiler?
i = i+++i; // + ++i or i++ + i? = i---i; // - --i or i-- - i?
i = + i++; //returns 2, expecting 3
know post increment. value used first , incremented. equivalent to
i = + i; = i+1;
and pre-increment. value incremented first , used.
i = i++ + i; //returns 3
is equivalent to
i = i+1; = + i;
i = i+++i; // + ++i or i++ + i?
is interpretted
i = + 1; = + i;
and this
i = i---i; // - --i or i-- - i?
is interpretted as
i= i-1; = i-i;
Comments
Post a Comment