dimanche 24 décembre 2017

returns true for ((unsigned int)0-1)>0

I came across some c++ code which was like

if(((unsigned int)0-1)>0)
{
//do something
}

and the program executed the statements in the if block. Being curious, I tried the same in c, which did the same. My understanding is that the statements in the if block get executed if the expression in the if condition returns a bool value true. This means that ((unsigned int)0-1)>0 must be returning true. Why is this happening?

Aucun commentaire:

Enregistrer un commentaire