0

I know that an assignment can be used as a condition in () after if statement. Like

int i;
if(i = 1) printf("Hey guys !");

. But It is unlike usual conditions like a < b , so I can`t understand its mechanism. Why can it works as a condition?

tsrrhhh
  • 459
  • 1
  • 5
  • 10
  • It will evaluate to 1. see http://stackoverflow.com/questions/9514569/what-does-an-assignment-return – Kinsey R Mar 29 '17 at 06:03
  • The point you have to understand is that `if` isn't limited to just some "conditions", you can write in any kind of expression; after it is evaluated, it is converted to `bool` (if it isn't already) and, if the result is `true`, the body of the `if` is executed. – Matteo Italia Mar 29 '17 at 06:08

0 Answers0