+ 4
Can any one explain why the output is different from one another programming language?
https://code.sololearn.com/cLekp2JxCN12/?ref=app https://code.sololearn.com/cf8fCSkqXJLl/?ref=app
20 Respostas
+ 9
The behavior is undefined in C. The result isn't just different from Java, but it might be different for every compiler you compile the code with
https://stackoverflow.com/questions/949433/why-are-these-constructs-using-pre-and-post-increment-undefined-behavior
+ 7
You can't say that the output is 2 in C because it is undefined behavior (see the link I posted). With another compiler you might get the same output as in Java, or something totally different
+ 7
Don't Forget Key Last attempt, but the output in C and C++ is actually undefined
+ 5
Anna have answered your question but you can still check on sequence point, that is what causes it actually which will arrive at undefine behavior
+ 4
Exactly đ
+ 4
The result are same: 2. Why? Just don't forget prefix and sufix operand and differences between + and ++, - and -- respectively.
+ 4
In case that interpreter/compiler make difference and gave us differently results, there's must be a problem in interpreter/compiler. Mathematic says completely solution and results.
+ 4
Of course, if 2 + 2 equal to 4, 1 AND 0 equal 0, 1 AND 1 equal to 1, 0 OR 1 equal to 1... That what I would to say.
+ 4
If you fist add value and, after that, make some action with variable, naturally that variable doesen't contain old value.
+ 3
Yes Don't Forget Key . You're right. Pardon me for my quick answer without checking result.
+ 3
Don't Forget Key I try to resolve question by looking at code, not test it.
+ 2
No, I'm not confused with logical ops Don't Forget Key. I just follow logic đ€Ł P.S. AND, OR, NOT, NAND, NOR, XAND, XOR (eXclusive OR)...đ I've got A in Mathematics Logic đ
+ 2
Why the result are 1 for me? I used Xperia XZ3 Don't Forget Key
+ 2
Well, you add a comment after line now Don't Forget Key. It's okay. After all, variable "i" was inrement by one. In other words, variable "i" increments after other operations. If you work with ++i clause, than i was pre-increment. Good job đ