首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

C常见有关问题之用枚举类型模拟bool类型

2013-10-18 
C常见问题之用枚举类型模拟bool类型ANSI C中是没有bool类型的,C99中引入了bool类型,具有true(也就是1)和fa

C常见问题之用枚举类型模拟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;}

热点排行