美文网首页
C语言数据类型

C语言数据类型

作者: 何亮hook_8285 | 来源:发表于2021-09-26 02:25 被阅读0次

整型类型

#include <stdio.h>
//查看类型范围
#include <limits.h>

int main()
{
    //短整型
    short  int sint=0;
    //整型
    int i=0;
    //长整型
    long  int lint=0;
    //最大的长整型
    long long  ll=0;

    //使用sizeof() 长度类型大小
    size_t  size=sizeof(short  int);
     //%hd short decimal
    //%d decimal
    //%ld long decimal
    //%lld long long decimal
    //\n new line
    printf("short int %d\n",sizeof(short  int ));
    printf("int %d\n",sizeof(int ));
    printf("long int %ld\n",sizeof(long int));
    printf("long long %lld\n",sizeof(long long));

    //最小范围 最大范围
    printf("max int %d,min %d \n",INT_MIN,INT_MAX);
    printf("max int %lld,min %lld \n",LLONG_MIN,LLONG_MAX);
    printf("unsigned max int %u ,unsigned min %d\n",UINT_MAX,0);

    //%x hex 十六进制整数  
    printf("int to hex %x\n",2);
    //%o oct 八进制数
    printf("int to oct %o",2);
    return  0;
}

字符类型

#include <stdio.h>
#pragma execution_character_set("utf-8")
int main()
{

    //字面量
    // \n newline
    // \b backspace
    // \r return
    // \t table
    // \' 转移 '
    // \" 转移 "
    //字符 对应就是ASCII码 127个
    char a='a'; //97
    char c1='1'; //49
    char c2='0'; //48
    char  i=0; // \0,NULL

    printf("char a:%d\n",a);
    printf("char c1:%d\n",c1);
    printf("char c2:%d\n",c2);
    printf("char i:%d\n",i);

    //%c 打印字符
    printf("char a:%c \n",a);

    // \ 8进制
    char ch_oct='\61';
    // \x 16进制
    char ch_hex='\31';

    printf("8 oct=%o \n",ch_oct);
    printf("16 hex=%x \n",ch_hex);

    wchar_t  zhong=L'中';
    wchar_t zhong_hex=L'\u4E2D';
    printf("%d\n",zhong);
    printf("%d\n",zhong_hex);

    //字符串
    char *str="hello world he liang";
    printf("str =%s",str);

}

浮点型

#include <stdio.h>

int main()
{

    float  a_float=3.14f; //6 +-10^-37~10^37
    printf("size of float : %d\n",sizeof(float ));
    double a_double=3.14; //15~16
    printf("size of double:%d\n",sizeof(double ));
    return 0;
}

相关文章

网友评论

      本文标题:C语言数据类型

      本文链接:https://www.haomeiwen.com/subject/lvixnltx.html