Search code examples
c++11if-statementincrementcontrol-flow

Using increment inside an if statement


What is the difference between if(++x < 0){something} and if(x + 1 < 0){something}

Thanks in advance


Solution

  • The ++x increments the value of x immediately by 1 and this new value of x is compared with 0.

    While x+1 does not increment the value of x and it's original value remains the same, only the output of x+1 is compared with 0.