Page 47 - PIC18F4550微處理機C語言設計實務
P. 47

૵ሔଡ଼ΥႧԊձ C ႧԊ 1




                       Չʕᄳίᜊᅰ a ʘۃٙ ++ ၾ –– ఱ݊჈ᄣ༶ၑɿ€Increment operatorၾ჈ಯ༶
                 ၑɿ€Decrement operatorf

                       ჈ᄣא჈ಯ༶ၑɿᅠᄳίᜊᅰʘۃאʘܝdՇ٫݊Ϟࢨйٙdਗ਼჈ᄣ€჈ಯ༶

                 ၑɿᅠᄳίᜊᅰۃࣛdڌͪ΋ਗ਼ᜊᅰٙ࠽̋€ಯ1d್ܝΎෂΫᜊᅰٙ࠽dਗ਼჈ᄣ
                 €჈ಯ༶ၑɿᅠᄳίᜊᅰʘܝdڌͪ΋ෂΫᜊᅰ࠽d್ܝΎ࿁ᜊᅰ̋€ಯ1f

                 Էνj

                   int a = 0;  int c = 0;
                   c = ++a;  /* ޴຅׵ a=a+1; c=a; ΋჈ᄣΎෂഗ cdഐ؈ c=1da=1f
                   c = --a;  /* ޴຅׵ a=a-1; c=a; ΋჈ಯΎෂഗ cdഐ؈ c=0da=0f


                   int a = 0;  int c = 0;
                   c = a++;  /* ഃ׵ c=a; a=a+1; ΋ෂഗ c Ύ჈ᄣdc=0da=1f
                   c = a--;  /* ഃ׵ c=a; a=a-1; ΋ෂഗ c Ύ჈ಯdc=1da=0f

                 ■ 指定運算子(Assignment operator)

                       ܸ֛༶ၑɿdҢࡁʊ຾޶ཀɓࡈܸ֛༶ၑɿٜટண֛ =dԫྼɪܸ֛༶ၑɿᒔϞ

                 ˸ɨٙ఻ࡈj

                               運算子符號            範例                      功能說明
                                  +=           a += b     a = a + b
                                  –=           a –= b     a = a – b

                                   *=          a *= b     a = a * b
                                   /=          a /= b     a = a / b€̥՟ਠ

                                  %=           a %= b     a = a % b€̥՟ቱᅰ
                                  &=           a &= b     a = a & b
                                   |=           a |= b    a = a | b
                                  ^=           a ^= b     a = a ^ b

                                  <<=          a <<= b    a = a << b  // ਗ਼ a ̸୅ b ࡈЗʩ್ܝπΫ a
                                  >>=          a >>= b    a = a >> b  // ਗ਼ a ̛୅ b ࡈЗʩ್ܝπΫ a


                       வԬ༶ၑɿ߰ᄳίɓৎdɦӚϞ͜ʃܼ໮ਜཞ݊ϞՉᎴ΋නҏdΝɓᗳۨٙ༶ၑ
                 ɿᄳίۃࠦٙึ΋ੂБdШ݊Ԩʔ݊הϞᄳίۃࠦٙ༶ၑɿ೻όேึ΋ੂБdʔΝᗳ

                 ۨٙ༶ၑɿึ࣬ኽ̴ٙᎴ΋නҏԸੂБdה˸ܔᙄᄳ೻όᒔ݊ࠅ୦࿕͜ʃܼ໮ਗ਼Іʊ
                 ซࠅٙᎴ΋නҏਂλਜཞd˸еੂБഐ؈ၾ຅ڋணซٙʔΝdֵɨఱΐ̈வԬ੬͜༶
                 ၑɿୌ໮ٙᎴ΋නҏf

                                                                                                             37
   42   43   44   45   46   47   48   49   50