if(valu)与if(valu ==true)

时间:2020-03-04 20:57:22   收藏:0   阅读:73

1.相关知识点

  if(valu)//如果valu非零,则为真

  if(valu==true)//当valu为布尔型,为真。当val不是布尔型时,true转换为1

#include<iostream>
using namespace std;
int main()
{
    int val = 3;
    if (val == true)
    {
        cout << val <<endl;
    }
    else 
    {
        cout << "值为假1" << endl;
    }
    if(val)
    {
        cout << val << endl;
    }
    else
    {
        cout << "值为假2" << endl;
    }
    return 0;
} 

 

原文:https://www.cnblogs.com/gjbhpu0308/p/12416066.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!