Need help

#include <iostream>
using namespace std;

int main() {
short i;
i=3;
++i++=++i++;
cout << i;
return 0;
}


Can someone please explain this. (how it works etc..)
My professor in high school gave me this problem to solve and I don't know how.
Last edited on
It doesn't work. It doesn't compile.
It does not work.

It does not even compile because ++i++ is invalid C++. It is parsed as ++(i++), but the result of i++ is rvalue (a value with no memory location), and any ++ requires an lvalue (a value with a memory location, something it can write to)

You could make it compile as ++++i=++++i, but that would still be an error since you can't increment the same variable more than once in the same expression (this would compile, but produce arbitrary results at run time)
Topic archived. No new replies allowed.