Basically, how does an if-statement analize whether an integer is true or false? These two simple lines print out "Hello", with a positive integer 764:
int a=764;
if(a){ cout<<"Hello"; }else{ cout<<"Bye"; } //Hello
If i change the integer from positive to negative (-231) it prints out "Hello" as well:
int a=-231;
if(a){ cout<<"Hello"; }else{ cout<<"Bye"; } //Hello
But if i set a
to be 0
, it gets false
int a=0;
if(a){ cout<<"Hello"; }else{ cout<<"Bye"; } //Bye
It goes true
with the range of a long int
, from -2147483647
to 2147483647
with only one exception: 0
. How does that happen? And what is that if
actually doing to determine so?
Aucun commentaire:
Enregistrer un commentaire