• <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>

            EverSpring working shop

            To pursue creative ideas based on nature.

            統(tǒng)計

            留言簿(1)

            他山之石

            閱讀排行榜

            評論排行榜

            The Remark of Usage for ++ and --

            Frankly, I am still very confused with the rule for the usage of the ++ and -- in the expression.
            Just try some execise in the g++, it seems that the rule for ++/-- is:

            As post-increment (X++) or post-decrement (X--), it alaways takes effect after the whole expression is done, even after the assignment is completed;
            As pre-increment (X++) or pre-decrement (X--), the ++/ -- firstly takes effect at the place where it is, and then the expression is executed.

            For example:
            A)
            ?? int incr = 3;
            ?? incr = (incr++)*4 + (incr++)*3 + 4;

            After the execution, the incr is 27.
            Steps:
            1. incr = 3*4 + 3*3 + 4 = 25;
            2. incr = incr + 2 = 27.

            B)
            ??? incr = 3;
            ??? incr = (incr--)*4 + (incr--)*3 + 4;

            Result incr is 23;

            C)
            ??? incr = 3;
            ??? incr = (--incr)*4 + (--incr)*3 +? (++incr) * 4;
            Result is 19.
            Steps:
            1. incr = (3-1)*4 + (2-1)*3 + (1+1)* 4 = 19

            D)
            ?? incr = 3
            ?? incr = (--incr)*4 + (--incr)*3 +? (++incr) * 4 + (incr++);
            Result is 22
            Steps:
            1. incr = (3-1)*4 + (2-1)*3 + (1+1)*4 + 2 = 21
            2. incr ++ -> incr = 22.


            REMARK Here!

            posted on 2009-02-21 20:00 everspring79 閱讀(326) 評論(1)  編輯 收藏 引用 所屬分類: Notes

            評論

            # re: The Remark of Usage for ++ and -- 2009-02-21 21:20 everspring79

            Another Remark - The evil resides in the combination of below operations:

            1) ++/--
            2) Macro
            3) Function Parms
            4) Condition Operation.

            Example:
            A)
            int foo(a, b, c)
            {
            return (a+b+c);
            }

            void main()
            {
            int aa = 5, bb = 4, cc = 3, result;

            result = foo(aa++, --bb, cc); // result = (5+3+3), aa = 6 now, bb = 3
            result = foo(aa++, ++aa, cc); // result = (7+7+3), aa = 8 now
            }

            B)
            #define MIN(a,b) (((a)<=(b))?(a):(b))

            int a = 10, b = 7
            d = MIN(++a, b);
            //May work well according to gcc.
            // d = 7, a still = 10
            d = (((a++)<=(b))?(a++):(b)) //as the condition is false, the second a++ will not execut.
            // d = 7, a = 11
            a = 7;
            b = 10;
            d = (((a++)<=(b))?(a++):(b)) //as the condition is true, the second a++ is executed, a= 9, but d = 7
            d = (((a++)<=(b))?(++a):(b)) // as the condtiion is true, the 2nd ++a is executed, this leads to d to be 9, finally a = 9.
            //above is an evil. the first a++ will lead a to be 7+1 before ?.
            a = 9; b=10
            d= (((a++)<=(b))?(a++):(b)) // antoher evil, the d = 10 because the d is assigned by a = 10 before the 2nd a++. After this a = a+1. so the result is d = 10, a =11.

              回復(fù)  更多評論   

            久久精品国产2020| 久久激情五月丁香伊人| 久久精品国产男包| 99久久国产热无码精品免费| 国产精品久久新婚兰兰| 久久久久亚洲AV片无码下载蜜桃 | 波多野结衣AV无码久久一区| 久久亚洲精品无码AV红樱桃| 狠狠狠色丁香婷婷综合久久五月| 狠狠干狠狠久久| 精品久久人人爽天天玩人人妻| 无码国产69精品久久久久网站| 国产AV影片久久久久久| 久久久无码精品亚洲日韩京东传媒| 久久99国产亚洲高清观看首页| 性高朝久久久久久久久久| 女人香蕉久久**毛片精品| 7777精品伊人久久久大香线蕉| 国产激情久久久久影院老熟女免费 | 免费观看成人久久网免费观看| 国产69精品久久久久久人妻精品| 免费观看成人久久网免费观看| 无码日韩人妻精品久久蜜桃 | 欧美激情一区二区久久久| 亚洲一区中文字幕久久| 欧美va久久久噜噜噜久久| 亚洲精品久久久www| 久久精品免费网站网| 久久精品国产亚洲77777| 久久精品aⅴ无码中文字字幕不卡 久久精品成人欧美大片 | 囯产精品久久久久久久久蜜桃| 亚洲国产精品无码久久青草| 人人狠狠综合久久亚洲婷婷| 丁香狠狠色婷婷久久综合| 色欲av伊人久久大香线蕉影院| 久久精品综合网| 久久久久国产精品嫩草影院| 久久精品国产男包| 伊人久久大香线蕉AV一区二区| 久久e热在这里只有国产中文精品99 | 国产69精品久久久久观看软件|