-3

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.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
kikiotsuka
  • 79
  • 8

1 Answers1

2

The result is undefined for C/C++ by the specification because the order of evaluation is not specified. See this answer for details.

Community
  • 1
  • 1
Dwayne Towell
  • 8,154
  • 4
  • 36
  • 49