跳至內容

stdbool.h

本頁使用了標題或全文手工轉換
維基百科,自由的百科全書

stdbool.hC語言標準函數庫中的一個頭文件,在C99中引入,包含四個用於布爾型預定義宏

宏定義[編輯]

IEEE 1003.1-2001標準中的宏定義包括:

  • bool,會擴展為_Bool
  • true,會擴展為1
  • false,會擴展為0
  • __bool_true_false_are_defined,會擴展為1

示例[編輯]

如下例所示:

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int main(void) {
    bool keep_going = true;  //也可以是`bool keep_going = 1;`
    while(keep_going) {
        printf("本程序会在keep_going为真时持续运行。\n");
        keep_going = false;    // 也可以是`keep_going = 0;`
    }
    printf("停止运行!\n");
    return EXIT_SUCCESS;
}

該程序會輸出

本程序会在keep_going为真时持续运行.
停止运行!

外部連結[編輯]