How is if statement evaluated in c++?
问题 Is if ( c ) the same as if ( c == 0 ) in C++? 回答1: No, if (c) is the same as if (c != 0) . And if (!c) is the same as if (c == 0) . 回答2: I'll break from the pack on this one... " if (c) " is closest to " if (((bool)c) == true) ". For integer types, this means " if (c != 0) ". As others have pointed out, overloading operator != can cause some strangeness but so can overloading " operator bool() " unless I am mistaken. 回答3: If c is a pointer or a numeric value, if( c ) is equivalent to if( c !=