How do you understand xPP+x in CPP?

ask a weak question.

    int x = 10;
    x += (xPP)+x;
    cout << x << endl;
    // 32

my understanding is x = x + (xPP) + x = 31. Should it be understood as x = (xPP) + (xPP) + x or x = x + (xPP) + (xPP)?

is it true that the addition operation should be performed at the end of the addition operation for the variable yroomroomz = ytransiz?

Thank you first!

CPP
Mar.10,2021

x = x + (xPP) + x = 10 "11" 11 "32
in the last x, because xPP has been executed before, the x has changed.


Xbox = xPP+x;
according to the greedy matching principle of the c language, it will be considered as x = (xPP) + x = 11 at + =, xPP+x is 10: 11, and finally should be 11: 10: 11, but this is my own guess, this behavior of modifying the value of variables many times in an expression is that ub, can have different results due to different compilers.


The

post operator PP does not complete the + 1 operation on the variable until the end of the execution of the whole statement, but the variable State and the operator PP, so state + = (statePP) + state, is equivalent to 11 + = 10 + 11. In the end, it equals 32.

In fact, you can understand this question by disassembling it. The high-level language hides a lot of implementation details, and taking a look at the assembly can give you a clearer understanding. To put it bluntly, the compiler hides the processing details of different grammar too deeply. Officially, there are grammar and related spec, but some abstractions are not as convenient as disassembly.

in order to deepen understanding, you can, but should avoid such code, the readability is too poor.


my understanding: X = x + (xPP) + x = (x + (xPP)) + x) = 10 "11" 11 "32; parenthesis operation is the highest, the first x is 10, the last x is 11;

Menu