• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            woaidongmao

            文章均收錄自他人博客,但不喜標題前加-[轉貼],因其丑陋,見諒!~
            隨筆 - 1469, 文章 - 0, 評論 - 661, 引用 - 0
            數據加載中……

            C語言詳解 - 表達式和語句

            1. 什么是表達式?

            C語言中的表達式一種有值的語法結構,它由運算符將變量、常量、函數調用返回值結合而成。

            1.1 變量

            變量名本身是一個表達式,表達式的值是變量當前的值。復雜的表達式由[], ->, ., 和單目運算符*構成。

            1.2 常量

            常量名本身是一個表達式,字面常量也是表達式。對于這兩者,表達式的值是常量當前的值。

            1.3 函數調用

            對于返回值不為void的函數,對它的正確調用也是表達式。表達式的值為函數的返回值。

            1.4 操作符

            運算符用于連接表達式中的值。以下是C語言中的運算符,運算符的優先級,及運算符的結合順序

            Order

            Category

            Operator

            Operation

            Associativity

            1

            Highest precedence

            ( )
            [ ]

            : :
            .

            Function call

            L → R
            Left to Right

            2

            Unary

            !
            ~
            +
            -
            ++
            - -
            &
            *
            Size of

            Logical negation (NOT)
            Bitwise 1’s complement
            Unary plus
            Unary minus
            Pre or post increment
            Pre or post decrement
            Address
            Indirection
            Size of operant in bytes

            R → L
            Right -> Left

            3

            Member Access

            .*
            →*

            Dereference
            Dereference

            L → R

            4

            Multiplication

            *
            /
            %

            Multiply
            Divide
            Modulus

            L → R

            5

            Additive

            +
            -

            Binary Plus
            Binary Minus

            L → R

            6

            Shift

            <<
            >>

            Shift Left
            Shift Right

            L → R

            7

            Relational

            <
            <=
            >
            >=

            Less than
            Less than or equal to
            Greater than
            Greater than or equal to

            L → R

            8

            Equality

            ==
            !=

            Equal to
            Not Equal to

            L → R

            9

            Bitwise AAND

            &

            Bitwise AND

            L → R

            10

            Bitwise XOR

            ^

            Bitwise XOR

            L → R

            11

            Bitwise OR

            |

            Bitwise OR

            L → R

            12

            Logical AND

            &&

            Logical AND

            L → R

            14

            Conditional

            ? :

            Ternary Operator

            R → L

            15

            Assignment

            =
            *=
            %=
            /=
            +=
            -=
            &=
            ^=
            |=
            <<=
            >>=

            Assignment
            Assign product
            Assign reminder
            Assign quotient
            Assign sum
            Assign difference
            Assign bitwise AND
            Assign bitwise XOR
            Assign bitwise OR
            Assign left shift
            Assign right shift

            R → L

            16

            Comma

            ,

            Evaluate

            L → R

             

            1.5 實例

            /* 變量常量表達式 */
            a
            sum
            1
            0.5
            PI

            /* 算術表達式 */
            a + b
            a - b + c
            a * b +
            'A'
            a / b - c +
            10
            i++ + i++ + ++i

            /* 賦值表達式 */
            a = b
            a *= b +=
            20
            a = b = c =
            10
            a = (b=
            4) / (c=2)

            /* 逗號表達式 */
            1+2, 3+4
            (
            10, a*5), a+10

            /* 關系表達式 */
            x == y
            x <= y
            x != y

            /* 邏輯表達式 */
            10 && 20
            0 || 1
            (a>b) && (!
            0)

            clip_image001clip_image001

            /* 復合表達式 */
            x = ( y = (a + b), z=
            10)

            /* 表達式的應用 */
            if( !100 ) //!100為邏輯表達式
              printf("expression show!");

            for(int i=10; i<10; i++)//for包含3個表達式,分別為i=10  i<10  i++
              printf("expression show!");

            while( 1 ) //1也是一個表達式
            {
                printf(
            "death loop!");
            }

            clip_image001clip_image001

             

            2. 語句

            語句指的是當程序運行時執行某個動作的語法結構。它改變變量的值,產生輸出,或處理輸入。C語言包括4類語句:

            2.1 表達式語句

            表達式語句是最簡單的一種語句,在表達式的末尾加分號就形成了一個表達式語句。表達式語句有以下形式:

            expression;

            最常用的表達式語句是函數調用語句和賦值語句。函數調用語句也屬于表達式語句,因為函數調用(sin(x) )也屬于表達式的一種。賦值語句的作用是將等號左邊變量的值改成等號右邊表達式的值。賦值語句最常用的形式為:

            variable = expression;

            實例:

             

            x = 10;
            y =
            20;
            x *=
            10;   

            1;
            x + y;
            //這些語句也是合法的。語句被執行時,表達式求值,但結果并不保存于任何地方
            getchar(); //讀取輸入中的下一個字符,但接著便將其丟棄!

            x++;
            printf(
            "hello \n"); //printf函數的返回值通常并不關心。所謂語句沒有效果只是表示表達式的值被忽略。

             

            2.2 語句塊

            可以用{  }將一系列語句括起來使其大功能上相當于一條語句,這就是語句塊。語句塊中可以有變量聲明,聲明必須位于塊的開始。

            實例:

             

            clip_image001

            int x;
            int y;
            x =
            6;

            {
               
            int z = 100;
                y = z/x;
                printf(
            "%d \n", y);
            }

            clip_image001

             

            2.3 空語句

            即只有一個分號的語句,它什么也不做。當用在循環體中時,表示循環體什么也不做。

            實例:

            ; //空語句

            for( int i=0; i<10; i++ )
            ;
            //循環體為空

             

            2.4 控制語句

            控制語句分類3類:循環語句,選擇/條件語句,特殊語句

            Repetition

            While Loops

            -

            pretest loops

            For Loops

            -

            pretest loops

            Do-While Loops

            -

            posttest loops

             

             

             

            /* While Loops */
            while (conditional-expression) {
                nested-statements
            }

            /* For Loops */
            for (initialization; conditional-expression; increment) {
                nested-statements
            }

            /* Do-While Loops */
            do {
                nested-statements
            }
            while (conditional-expression);

             

            Conditional Execution And Selection

            If Statements

            -

            conditional execution of a single statement

            If-Else Statements

            -

            conditional selection among two statements

            Switch Statements

            -

            conditional selection among several statements

            Extended If Statements

            -

            conditional selection among several statements

             

             

             

            /* If Statements */
            if (conditional-expression) {
                then-clause
            }

            /* If-Else Statements */
            if (conditional-expression) {
                then-clause
            }
            else {
               
            else-clause
            }

            /* Switch Statements */
            switch (control-expression) {
               
            case constant-expression-1:
                statements-
            1
                    .
                    .
                    .
               
            case constant-expression-n:
                statements-n
               
            default:
               
            default-statements
            }

            /* Extended If Statements */
            if (conditional-expression-1) {
                statements-
            1
            }
            else if (conditional-expression-1) {
                statements-
            1
                .
                .
                .
            }
            else if (conditional-expression-n) {
                statements-n
            }
            else {
               
            default-statements
            }

             

            Special Control Statements

            Return Statements

            -

            return values from and terminate functions

            Continue Statements

            -

            skip the remaining statements in an iteration of a loop

            Break Statements

            -

            exit a loop or switch statement

            /* Return Statements */
            return;
            return expression;

            /* Continue Statements */
            continue;

            /* Break Statements */
            break;

             

            實例略

             

            Tag標簽: 表達式,語句

            jcsu
            關注 - 1
            粉絲 - 1

            關注博主

             

            posted on 2010-05-06 12:09 肥仔 閱讀(2173) 評論(0)  編輯 收藏 引用 所屬分類: 狀態機 & 自動機 & 形式語言

            人妻无码αv中文字幕久久| 久久精品一区二区三区中文字幕| 久久精品中文字幕第23页| 久久久国产精品亚洲一区| 亚洲国产一成人久久精品| 久久国语露脸国产精品电影| 精品水蜜桃久久久久久久| 国产精品九九九久久九九| 国内精品久久久久影院薰衣草 | 久久精品国产乱子伦| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 99久久精品免费看国产一区二区三区 | 久久久这里只有精品加勒比| 97久久精品人人做人人爽| 狠狠色丁香婷婷久久综合不卡| 久久久国产乱子伦精品作者 | 久久精品国产亚洲一区二区| 2021精品国产综合久久| 国产精品久久久亚洲| 国产精品久久自在自线观看| 91精品国产91热久久久久福利| 日本精品久久久久中文字幕8| 色综合色天天久久婷婷基地| 国产精品gz久久久| 香蕉aa三级久久毛片| 狠狠综合久久AV一区二区三区| 亚洲av伊人久久综合密臀性色| 国产精品久久久久AV福利动漫| 国产精品久久永久免费| 久久久久亚洲av成人无码电影| 亚洲精品无码久久久| 午夜天堂精品久久久久| 狠狠色丁香久久综合五月| 久久这里有精品视频| 国产亚洲精品久久久久秋霞| 996久久国产精品线观看| 国产精品伊人久久伊人电影 | 性做久久久久久免费观看| 久久中文字幕人妻丝袜| 久久亚洲国产午夜精品理论片| 人妻无码久久精品|