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

            統計

            留言簿(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.

              回復  更多評論   

            久久99国产精品久久99果冻传媒| 国产精品99久久久精品无码| 国产精品久久久久久久久软件 | 久久久久久国产精品无码下载 | 大香网伊人久久综合网2020| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 久久精品人人做人人爽电影蜜月| 9久久9久久精品| 亚洲一区精品伊人久久伊人| 亚洲国产精品18久久久久久| 国内精品久久久久久不卡影院 | 国产69精品久久久久APP下载| 国产精品9999久久久久| 欧美激情精品久久久久久| 99精品久久精品一区二区| 伊人久久亚洲综合影院| 久久亚洲国产午夜精品理论片| 欧美与黑人午夜性猛交久久久| 国产精品青草久久久久婷婷 | 一本大道加勒比久久综合| 亚洲伊人久久成综合人影院| 中文字幕亚洲综合久久2| 色88久久久久高潮综合影院| 一本色道久久综合狠狠躁篇 | 久久久久亚洲精品无码蜜桃| 久久久网中文字幕| 国产成人99久久亚洲综合精品| 欧美va久久久噜噜噜久久| 狠狠色丁香婷婷久久综合| 亚洲精品乱码久久久久久蜜桃| 成人精品一区二区久久| 天天综合久久久网| 日本道色综合久久影院| 国内精品久久国产大陆| 成人资源影音先锋久久资源网| 久久久久亚洲AV无码网站| 久久精品无码专区免费东京热| 日本强好片久久久久久AAA| 欧美亚洲国产精品久久高清| 久久亚洲日韩看片无码| 97精品依人久久久大香线蕉97|