Page 47 - PIC18F4550微處理機C語言設計實務
P. 47
ሔଡ଼ΥႧԊձ C ႧԊ 1
Չʕᄳίᜊᅰ a ʘۃٙ ++ ၾ –– ఱ݊ᄣ༶ၑɿIncrement operatorၾಯ༶
ၑɿDecrement operatorf
ᄣאಯ༶ၑɿᅠᄳίᜊᅰʘۃאʘܝ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