If Statements 
  May 6, 2011 at 9:08pm UTC  
 
This has been really bugging me. I see codies using 
if  statements like this:
1 2 3 
int  Variable( 10 );
if ( Variable )
    // do something...  
 
I don't understand it. What is it testing for? Can anybody explain this? 
 
 
 
 
 
  May 6, 2011 at 9:12pm UTC  
 
It's testing whether Variable's value is non-zero.
Last edited on May 6, 2011 at 9:12pm UTC  
 
 
 
 
  May 6, 2011 at 9:15pm UTC  
 
Simple enough. Thanks, Filipe.
 
 
 
 
  May 7, 2011 at 12:38am UTC  
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 
int  n = ...;
bool  b = n; //implicit cast 
//now 
if ( n == 0 )
	assert( b == false  );
else 
	assert( b == true  );
//or 
if ( b )
	assert( n != 0 );
else 
	assert( n == 0 );
 
 
 
 
 
Topic archived. No new replies allowed.