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

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




                   1-3-8  運算式與運算子


                 ■ 算術(Arithmetic)運算子:+、–、*、/、%、++、––


                       Ϟ̋€+eಯ€–e࠱€*eৰ€/€̥՟ਠٙ༶ၑɿd̤̮ᒔϞɓࡈ
                 ɰ੬ٙ͜՟ቱᅰ༶ၑɿ€%dவᗳ˸ᅰኪ༶ၑމ˴ٙ༶ၑɿd၈ʘމၑஔ༶ၑɿ
                 €Arithmetic operatorf


                                    運算子符號            範例                 功能說明
                                        +           c = a + b  c ഃ׵ a ̋ b
                                        –           c = a – b  c ഃ׵ a ಯ b

                                         *          c = a * b  c ഃ׵ a ࠱ b
                                         /          c = a / b  c ഃ׵ a ৰ˸ b ٙਠ
                                        %           c = a % b  c ഃ׵ a ৰ˸ b ٙቱᅰ


                       வᗳ༶ၑɿٙԴ͜dਿ͉ɪ̸͟Ͼ̛ආБ༶ၑd༾Ց̋ಯ࠱ৰٙනҏਪᕚࣛdɰ
                 ݊΋࠱ৰܝ̋ಯd̀ࠅࣛ̋ɪܼ໮Ըᅂᚤ༶ၑٙ΋ܝනҏf

                 Էνj


                   char a,b,c;   // ܁ѓ 3 ࡈᜊᅰ
                   a = 8;        // ਗ਼ 8 ׳ɝᜊᅰ a ʕ
                   b = 5;        // ਗ਼ 5 ׳ɝᜊᅰ b ʕ
                   c = a+b;      // ̋ج༶ၑ c=8+5=13
                   c = a-b;      // ಯج༶ၑ c=8-5=3
                   c = a*b;      // ࠱ج༶ၑ c=8*5=40
                   c = a/b;      // ৰج༶ၑ՟ਠ c=8/5=1
                   c = a%b;      // ৰج༶ၑ՟ቱᅰ c=8%5=3


                 ■ 關係(Relational)運算子:>、>=、<、<=、==、!=

                       ᅰኪɪϞՇᅰਂˢ༰ٙ༶ၑdˢ༰ٙ༶ၑഐ؈̥Ϟॆ€True = 1ձ৽€False =
                 0f྅݊ɽ׵eഃ׵eʃ׵ഃdவԬ༶ၑɿ၈މᗫڷ༶ၑɿdϞɽ׵€>eɽ׵ഃ

                 ׵€>=eʃ׵€<eʃ׵ഃ׵€<=eഃ׵€==eʔഃ׵€!=fᗫڷ༶ၑɿ
                 ̙˸͜׵ ifewhile א for ഃܸ˿ٙૢ΁кᓙɪࠦd߰ૢ΁ୌΥࣛഐ؈މॆ€Trued
                 ۆึੂБܝࠦٙਗЪd߰ૢ΁ʔୌΥࣛഐ؈މ৽€FalsedۆʔึੂБܝࠦٙਗЪd

                 ϾᗫڷόٙՇᗙ̙˸ே݊ᜊᅰdɰ̙˸ɓᗙᜊᅰ̤ɓᗙ੬ᅰdޟЇ̙˸݊ၑόאՌόf






                                                                                                             33
   38   39   40   41   42   43   44   45   46   47   48