bool and integer

Started by
3 comments, last by jflanglois 17 years ago
bool b_var = false; for (int i=0;i<10;i++) { b_var = i; } so what is b_var value?
Advertisement
True.

bool value of false is equivalent to 0, any other value is equivalent to true;
Quote:Original post by Antheus
True.

bool value of false is equivalent to 0, any other value is equivalent to true;


I thoguht -1 was false? :(
Crazyfool, some languages (QBasic, probably others) define false as 0, and true as -1, since in binary 0 is all 0's and -1 is all 1's (and hence true is a binary not of false).

C and C++ however treat any value except 0 as true.
Quote:Original post by sphen_lee
Crazyfool, some languages (QBasic, probably others) define false as 0, and true as -1, since in binary 0 is all 0's and -1 is all 1's

Sure, if your processor does calculations in twos complement.

[Edited by - jflanglois on April 5, 2007 11:42:47 PM]

This topic is closed to new replies.

Advertisement