學點 C 語言(12): 資料類型 – 整型(int)、字元(char)、浮點(float、double)

來源:互聯網
上載者:User
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;}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.