+ 7
I have seen ➕➕🅰️ problem somewhere before, but still no one explained it⁉️🤔
https://code.sololearn.com/cSzBTSHAJ8Hj/?ref=app ... & the same problem in C++ 😕 https://code.sololearn.com/clfwZ08z7Wcs/?ref=app ... & NO problem in Java, JS, C#, 🐍 https://code.sololearn.com/c7Mykgf4TrI1/?ref=app https://code.sololearn.com/WXAWXlRFPiaY/?ref=app https://code.sololearn.com/cvAZrIE2QsMi/?ref=app https://code.sololearn.com/cAxYA2hOk6V0/?ref=app https://code.sololearn.com/cXUqoLoE3oN1/?ref=app
7 ответов
+ 3
For cpp see the "Examples" section in the documentation:
https://en.cppreference.com/w/cpp/language/operator_incdec
+ 7
In C, the order of evaluating this expression is not specified (therefore the compiler dependency).
Not sure about Java, but a) there might be such a specification or b) some compilers might implement a specification.
In any case, multiple increments in the same line don't make sense and I wouldn't rely on the compiler to fix it :)
+ 6
Multiple increments in the same line is not a thing to do: It is undefined behavior and the result probably depends on the given compiler. That's what the warning is about to tell us.
If the program compiles, the resulting value is rather a garbage value – the 7 in your example case isn't meaningful, it could have been a totally different one, I guess
+ 3
Lisa
Maybe you are right but it's interesting that 🅰️ at the end becomes 3️⃣ /it's correct after a triple incrementation/⁉️🤔
+ 2
Lisa
I didn't even see the warning until I scrolled down, it's been confusing me for a while
+ 2
I still didn't get why 'undefined' error in C, If I do in Java I get A3, B6 without any warning.
+ 1
Janusz Bujak 🇵🇱
Yes, I'm not sure if this is what we should expect – because it is already surprising that the program even reaches the output for incremented A.
On the other hand, I'd guess it is not the process of incrementing itself that overtaxes the compiler. It's rather the chaining of the expressions (here addition) while the state of each term is indefinite. (Sorry, don't know how to express it better at the moment. Still need to think about if it makes sense at all 😅)