How does the increment operator work in an if statement?

前端 未结 7 1460
感情败类
感情败类 2021-01-13 14:16
    #include 

    int main()
    {
        int x = 0;

        if (x++)
            printf(\"true\\n\");
        else if (x == 1)
            printf(         


        
7条回答
  •  春和景丽
    2021-01-13 14:40

    Post increment means that it returns the current value (in this case for the purpose of the if) and increments it afterwards. It is equivalent to

    if(x) {
      x++;
      // ...
    } else {
      x++;
      // ...
    }
    

提交回复
热议问题