mercredi 6 janvier 2021

Is there any chance that the boolean expression is true but the program jumps to false statement?

I'm dealing with a logic bug and the code goes like this

uint8_t cond = 0;

// Something has been done here, then check the value of "cond"

if ((cond != 0) && (A)) { // A is always true, I'm just not sure about the value of "cond"
    printf("It's true, cond = %d", cond);
} else {
    printf("It's false, cond = %d", cond);
}

and the output is always like this:

It's true, cond = 0

The cond's value should be any number but 0 if the condition is true, right?

What should I check now?

Aucun commentaire:

Enregistrer un commentaire