黑馬程式員------C 語言學習筆記--- C語言資料類型

來源:互聯網
上載者:User

標籤:

黑馬程式員------<a href="http://www.itheima.com" target="blank">Java培訓、Android培訓、iOS培訓、.Net培訓</a>、期待與您交流! -------

1.1     C語言資料類型

01 整型資料

l 整型常量 十進位數:以非0數字開頭。八進位:以數字0開頭。十六進位:以0x或者0X開頭

l 整型變數 int , long int,  short int,

#include <stdio.h>int main(){#define PI 3.14    double r;    double h;    double s;    // 提示使用者輸入兩個數:半徑r, 高h    printf("請輸入半徑: 請輸入高:\n");    // 接受使用者輸入的資料    scanf("%lf%lf",&r,&h);        //計算結果    s = 2*PI*r*h + PI*r*r;        // 輸出結果    printf("圓柱體的表面積是%f\n",s);                return 0;}

 

02 實型資料

l 實型常量 十進位形式:0.12 0.55

指數形式:1.2e3 e的前面要有數字且後面的指數要為整數

*實型變數 float, double ,longdouble,

03 字元型資料

*字元常量 :是由單引號括起來的單個字元。如 ‘a’ ‘0’

* 字元變數 :字元變數是用來存放字元常量的

*字串常量:是有一對雙引號括起來的的字元序列,逸出字元’\0’作為結束標誌。

04 枚舉類型 :當一個變數的取值僅有有限幾種可能時,可以使用枚舉類型。

05 指標類型:指標類型是一種特殊的資料類型,儲存的數值被解釋為記憶體裡的一個地址

#include <stdio.h>int main(){    int i=0,j=0,x=10,y=10,z=10,t=10,b;    float f,f1,f2,f3;    /* 單目運算 */    x = -x;    y = ++i;    y = j++;    printf("x=%d,y=%d,z=%d\n",x,y,z);    printf("i=%d,j=%d\n",i,j);        /* 雙目運算 */      i = t%3;    j = t/3;    printf("i=%d,j=%d\n",i,j);        /*類型轉換*/    f = 10;    b = 2;    f1 = 1/b*100+10+f;    f2 = 1.0/b*100+10+f;    f3 = (float)1/b*100+10+f;        printf("f1=%f,f2=%f,f3=%f\n",f1,f2,f3);    

 

黑馬程式員------C 語言學習筆記--- C語言資料類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.