+ 3
How!! and the second answer is right?!!
#include <iostream> using namespace std; int main() { int x =5; cout<<x++<<x<<"\n"<<++x<<"\n"<<x<<endl; return 0; } -------_---------------------------------------- answer one: output this Code Editor 67 7 7 ================================ answer two : Output another Code Editor 56 7 7
6 odpowiedzi
+ 16
it is called undefined behaviour.
https://en.m.wikipedia.org/wiki/Undefined_behavior
I believe these examples are only ever meant to be thought exercises. they are bad either way as they often confuse the student more than help. see http://en.cppreference.com/w/cpp/language/operator_incdec
+ 12
seems odd to me. when the result can vary. i guess the compilers are all the same in the schools though
+ 6
@jay
These type of questions form the base of questions in computer science exams in my school.
And then teacher verifies the answer by making us compile the codes, which can be differently approached in undefined behaviour...
+ 6
@jay
Unfortunately, they are not.
Some still use Turbo.
Others including me use CodeBlocks.
+ 5
@Ahmed Salah El-Kholy
If you execute from left to right, yes.
If you execute from right to left, no.
That my friend, is the dilemma we face here...
+ 1
the second answer is right?!!