IOS成長中-C語言-資料類型(第一天)

來源:互聯網
上載者:User

標籤:ios   c語言   基礎資料型別 (Elementary Data Type)   基本輸入輸出   

定義常量
分三部分:資料類型 變數名 = 初值
    定義整型變數
       變數名的命名規則:
        1.變數名只能由數字,字母,底線組成,並且數字不能開頭。
        2.不能和系統關鍵字重名。
        3.具有自解釋性,見名知意。
        4.變數名不能重複。
        5.變數名由多個單片語成時,除了首個單詞首字母小寫外,其他的單詞首字母都要大寫   

    int a = 10;    float b = 1.0;//用於注釋一行。    char a = ‘a‘;

//       用於注釋一行

/*  */  用於注釋一段

    //練習1:    int a = 10;    int b = 5;    int c = 0;    int a = 10, b = 5, c = 0;    //賦值的過程是一個拷貝的過程。    c = a;//c 10,a 10,b 5    a = b;//c 10,a 5, b 5    b = c;//c 10,a 5, b 10    int maxAge = 10;
    //算術運算子    float a = 0;    a = 3.0 / 5;  //除法運算,除數不能為零。    printf("%f", a);    int a = 10;    int b = 3;    int c = 0;    c = a + b;    printf("%d\n", c);  // \n 換行。    c = a - b;    printf("%d\n", c);    c = a * b;    printf("%d\n", c);    c = a / b;    printf("%d\n", c);    c = a % b;    printf("%d\n", c);

++,自增1,--,自減1;
++,--在變數的前面,先執行++,--運算,再參與運算。

++,--在變數的後面,先參與運算,再++,--。

    c = a++; // c = a ; a =  a+ 1;    c = ++a; // a = a + 1; c = a;    c = a--; // a = a - 1; c = a;    c = a+++b;  //c = a++ + b;盡量結合成最大的計算單元。    printf("%d,%d,%d\n", c, a, b);

符合運算子,+=,-=,*=,/=,%=
符合運算子中間不能加空格。

    c += b; //c = c + b;    c = -6 % -4; //取餘運算子的兩端都必須為整數。    printf("%d\n", c);

基本的輸出函數
%d 整型(整數) %f 浮點型(小數) %c 字元型 %ld 長整型

    int name = 10;    printf("%d", name);    printf("\\");    int d = 0;
    //格式化輸入函數    scanf("%d", &d); //輸入操作,需要得到變數地址。    printf("%d", d);    int a = 0; int b = 0; int c = 0;    //從控制台輸入a, b的值。    scanf("%d%d", &a, &b);    printf("%d,%d", a, b);    float a = 10.2;    printf("%.2f", a); // %.2f代表小數點之後保留兩位
    /*作業1:    printf("  *  \n");    printf(" * * \n");    printf("* * *\n");    */    /*作業2:    float a = 0.00;    scanf("%f", &a);    a = a * 0.05 + a;    printf("%.2f\n", a);    */    /*作業3:    int a = 0;     int b0 = 0; int b1 = 0; int b2 = 0; int b3 = 0; int b4 = 0;    int c = 0;    scanf("%d", &a);    b1 = a / 20;    c = a % 20;    b2 =  c / 10;    c = c % 10;    b3 = c / 5;    c = c % 5;    b4 = c / 1;    b0 = b1 + b2 + b3 + b4;    printf("%d,%d,%d,%d,%d\n", b1, b2, b3, b4, b0);    */    /*作業4:    int a; int b;    scanf("%d%d", &a, &b);    printf("%d\n", a + b);    printf("%d\n", a - b);    printf("%d\n", a * b);    printf("%d\n", a % b);    */


本文出自 “IOS成長中” 部落格,謝絕轉載!

聯繫我們

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