在 C 语言中,if 条件中为 0 或假时,代码块将不会执行。而 !0 的结果是真,因此代码块将会被执行。
简单记忆: !0 和 true 执行! 0跳过,执行else
int main() {
const char* str2 = "world";
const char* str3 = "world";
//equal if(!0); if(true); if(_stricmp(str2, str3)==0); if (!_stricmp(str2, str3))
//not equal if(0); if (_stricmp(str2, str3)); if(!_stricmp(str2, str3)==0)
//结论1 !0 和 true 执行! 0跳过执行else
//
//结论2 if(_stricmp(str2, str3)==0) equal 《--- if(0=0) 条件为真,执行
// if(!_stricmp(str2, str3)==0) not equal. 《--- if(!0=0) 条件为假,跳过