mercredi 9 septembre 2020

Using an Int in the if condition [duplicate]

In my current class I am seeing a lot of times where my teacher puts a number as the condition of an if statement then asks for the output. I'm confused as to how these statements are being evaluated. Example:

if(-1) {
   x = 35;
}

or

if(0) {
   x = 35;
}

Why does it go inside the if statement instead of just ignoring it? What is making if(-1) evaluate true? And why does if(0) evaluate false?

This is an online class so I can't get help directly from the teacher usually. I have searched for a few hours on various websites about C for loops, but I haven't found anything relevant yet to my question.

Aucun commentaire:

Enregistrer un commentaire