For numeric variables (such as a), + and + + a statement is used to make the value of a variable on the basis of original increase 1
But +; Is in the use of a variable a once before since the increase on a 1 operation
For + + a is to use a first for the increased 1 operation the value of the
I usually use + is ascribed to add the values of a, a + + a is the first assignment again and again to remember them
Several example
Eg1: x=1
X++ + + + x=
Look from left to right, x++, x=2, x++=1;
Back again + + x, x=2, previously at this time on the 1 x, x=3=+ + x
So the final answer is 1 + 3=4
Eg2: assume that x=2,
So * (x++)/(+ + x) is the result of the 3 + x
Priority (add, subtract, multiply or divide and normal operation is the same, from left to right
+ + x x=2 at this time, add a first, namely + + x=3; The assignment again, x=3
X++ at x=3, ascribed value, namely x++=3; Add a, x=4
So the result is 3 * 3/3 + 4=7
Eg3: x=(x++)/2 o 3
X++ ascribed value, namely x++=2
So the result is two-thirds=0
Ps: devide/on both sides are integers, the answer is must be an integer,
Small white posts for the first time, personal understanding, there is an error at points out!
CodePudding user response:
BBS is used to discuss the problem, you post the final will be a variety of problems to brush, notes that if you write a blog, mobile payment column there can write blog, blog is very convenient later viewingCodePudding user response:
All wrongX++ + + + x
. Is undefined behavior
Results the meaningless
Your resolution is also wrong
CodePudding user response:
?????????? Ah... All wrong, that should be howCodePudding user response:
X++ + + + x=? You can't guessX++ and + + x are expressions (x is a variable), like x + 1, expression function and the value of two parts, is the function of x + 1 to + 1 x, its value is x + 1
Similarly x++ and + + x functions are made on the 1 x, different is that the former has a value of x from increasing the value of the former, the latter has a value of x since increased value, you can as this is the rules, there is no order, of course, in order to remember their values to understand so it doesn't matter
Ed since the increase and the decrease is not an option, the compiler is not the same as the result, it is hard to say how the order of operations, so some language simply limiting the increase since decreases only alone
CodePudding user response:
Precedence and associativity comprehensive look, in addition to study the undefined behavior, and then OKSuggestions: first, to find a reliable book book unreliable (tan), according to the book, don't own summary, finally to go online to find the standard or the analysis of the standard,
Supplement: don't say I IDE in XXX (compiler) the following result is such, so XXX, must according to the standard
CodePudding user response:
X++ + + + X each compiler is different, the results are different,When cases may use X++;
+ + X;
Try not to write X++ + + + X such
CodePudding user response:
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.htmlI hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html