Is `C == C++` undefined behaviour?

前端 未结 2 2022
野的像风
野的像风 2020-12-19 06:18

A friend tells me that after:

int C = anything;

C == C++ will have the value true. This is intended as a joke, a

2条回答
  •  粉色の甜心
    2020-12-19 06:49

    You are correct. Even the compiler says so: compiling

    #include 
    
    int main()
    {
      int C = 0;
      if (C == C++) {
      ...
    

    results in:

    main.cpp: In function 'int main()':
    main.cpp:6:17: warning: operation on 'C' may be undefined [-Wsequence-point]
         if (C == C++) {
                     ^
    

    (Coliru)

提交回复
热议问题