zoukankan      html  css  js  c++  java
  • 学点 C 语言(12): 数据类型 整型(int)、字符(char)、浮点(float、double)


    C 语言数据类型: 基本类型、构造类型、指针类型、空类型.

    基本类型又包括: 整型、字符、浮点(单精度、双精度)、枚举.

    构造类型又包括: 数组、结构体、公用体.


    1. 显示整型(int)的最小、最大值:
    #include <stdio.h>
    #include <limits.h>
    
    int main(void)
    {
        int n1,n2;
    
        n1 = INT_MIN;
        n2 = INT_MAX;
        printf("%d .. %d", n1,n2);
        
        getchar();
        return 0;
    }
    

    2. 显示单精度类型(float)的最小、最大值:
    #include <stdio.h>
    #include <float.h>
    
    int main(void)
    {
        float f1 = FLT_MIN;
        float f2 = FLT_MAX;
        
        printf("%e .. %e\n", f1,f2);
        
        getchar();
        return 0;
    }
    

    3. 显示双精度类型(double)的最小、最大值:
    #include <stdio.h>
    #include <float.h>
    
    int main(void)
    {
        double d1 = DBL_MIN;
        double d2 = DBL_MAX;
        
        printf("%e .. %e\n", d1,d2);
        
        getchar();
        return 0;
    }
    

    4. 显示字符类型(double)的最小、最大值:
    #include <stdio.h>
    #include <limits.h>
    
    int main(void)
    {
        char c1 = CHAR_MIN;
        char c2 = CHAR_MAX;
    
        printf("%d .. %d\n", c1,c2);
        printf("char 类型位数: %d\n", CHAR_BIT);
        
        getchar();
        return 0;
    }
    

    5. 关于字符类型变量(虽说 char 字符, 却常常把它当作 -128..127 小整数使用):
    #include <stdio.h>
    
    int main(void)
    {
        char c;
    
        c = 'A';  /* 单引号 */
        printf("%c\n", c);
    
        c = 65;
        printf("%c\n", c);
    
        c = 0x41;
        printf("%c\n", c);
    
        c = 0101; /* 开头为 0 是八进制 */
        printf("%c\n", c);
    
        c = 'B' - 1;
        printf("%c\n", c);
    
        c = 'B';
        c--;
        printf("%c\n", c);
    
        c = 'A';
        printf("%c\n", c);
        printf("%u\n", c);
    
        printf("%u\n", 'a'-'A');
    
        c = '\n';
        putchar(c);      
        
        getchar();
        return 0;
    }
    

  • 相关阅读:
    java自学
    java自学
    java自学
    java自学
    Interesting Finds: 2009 11.17 ~ 11.22
    Interesting Finds: 2009 10.09 ~10.13
    Interesting Finds: 2009 10.01 ~ 10.08
    Interesting Finds: 2009 10.14 ~ 10.21
    Interesting Finds: 2009 11.01 ~ 11.08
    Interesting Finds: 2009 10.25 ~ 10.31
  • 原文地址:https://www.cnblogs.com/del/p/1341939.html
Copyright © 2011-2022 走看看