Home > Back-end >  Ask a simple question
Ask a simple question

Time:10-22

int a;
Int m=3, n=4;
A=m++ - (n);

A why=0?

CodePudding user response:

A=m++ - (n)
According to the priority order - n m++ finally do subtraction operation
- n=3;
A=m++ - 3;
M++=3;
A=3-3;
A=0

CodePudding user response:

This has nothing to do with the priority order ~

A + + and - operators can be placed in variables before and after... Such as i++ or + + I are the same!

but if with other's fit and into operation... The meaning is not the same! + + or - in front of the variable... + + or - is in front of the other operator perform... The + + or - if after variable... Said it + + or - is performed after other operator!

A=m++ - (n) is an operation... This m++ has yet to be added in operation a... But - n in operation will be a reduction in the... So a=3 - (4-1) the result is zero... After the operation to perform... The m=4, n=3

CodePudding user response:

M++ is performed in accordance with the operator priority after on the increase - n is performed first decreases in the computing result is 0;

CodePudding user response:

2 floor very detailed explanation, I want to say is, in fact, when we use, generally used in an operation to a + + and - instead, too many logic is not clear, and different editor of + + or - difference algorithm, usually I use + 1 or - 1 instead
  • Related