设为首页 加入收藏

TOP

C常见问题之用枚举类型模拟bool类型
2014-11-23 21:45:51 来源: 作者: 【 】 浏览:7
Tags:常见问题 枚举 类型 模拟 bool
ANSI C中是没有bool类型的,C99中引入了bool类型,具有true(也就是1)和false(也就是0)两种值,但是需要包含头文件stdbool.h之后才可以使用。
我们完全可以用枚举类型来模拟bool类型,如下所示:
typedef enum{  
    false, true  
}bool;  
  
bool test(int a)  
{  
    if(a > 0){  
        return true;  
    }  
    else{  
        return false;  
    }  
}  
  
int main(void)  
{  
    bool result;  
    result = test(1);  
    return 0;  
}

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇[互联网面试笔试汇总C/C++-17] 链.. 下一篇C常见问题之exit

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: