My friend and I came upon an interesting joke C > C++
since he likes C over C++. However, I am curious as to the validity of executing that code segment. I ran and compiled
int C;
C = 1;std::cout << (C++ < C) << "\n";
C = 1;std::cout << (C < C++) << "\n";
C = 1;std::cout << (C++ > C) << "\n";
C = 1;std::cout << (C > C++) << "\n";
the output was 1 0 0 1 using C++98/C++11, and true, false, false, false for Java.
My question is how does the process of evaluation of these statement work? I get especially confused because C++ < C
and C > C++
contradict each other in Java, while staying consistent in C++, as well as the logic of C++ < C
, where supposedly the left and right sides are equal or the left side is greater than the right.