“C - C++” joke about postfix/prefix operation ordering

前端 未结 7 2159
长情又很酷
长情又很酷 2020-12-22 13:34

My friend sent me a joke:

Q. What\'s the difference between C and C++?

A. Nothing, because: (C - C++ == 0)

I tried to change

7条回答
  •  时光说笑
    2020-12-22 14:14

    Because the increment is performed before the operation in one case, whereas the increment is performed after the operation in the other case.

    int c = 10;
    System.out.println(c); // output 10
    System.out.println(c++); // outputs 10
    System.out.println(c); // output 11
    System.out.println(++c); // output 12
    System.out.println(c); // output 12
    

提交回复
热议问题