C语言数据类型

1、基本数据类型

 1.1 整数类型

 1.2 浮点类型

 1.3 字符类型

 

 

1.4 布尔类型

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

// 使用宏定义
#define TRUE 1
#define BOOL int

int main()
{
    // 第1种处理方式
    // c89中,如果想使用布尔类型的话,使用0表示false,使用1或非0表示true

    int handsome = 2;
    if (handsome)
    {
        printf("周日\n");
    }

    // 第2种处理方式,使用宏定义
    BOOL handsome1 = TRUE;
    if (handsome1)
    {
        printf("okk\n");
    }

    // 第3种处理方式
    // c99中,标准添加了类型_Bool,表示布尔值,即逻辑值true和false
    _Bool isBeauty = 1;
    if (isBeauty)
    {
        printf("美女\n");
    }

    // 第4种处理方式
    // c99还提供了一个头文件stdbool.h,文件中定义了'bool'代表'_Bool'
    bool isFlag = true;
    if (isFlag)
    {
        printf("olll\n");
    }

    return 0;
}

 bool类型是由头文件stdbool.h引入的类型,不属于基本数据类型。

posted @ 2024-04-28 20:40  意如柳  阅读(8)  评论(0)    收藏  举报