• <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)計(jì)

            留言簿(1)

            他山之石

            閱讀排行榜

            評(píng)論排行榜

            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) 評(píng)論(1)  編輯 收藏 引用 所屬分類: Notes

            評(píng)論

            # 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ù)  更多評(píng)論   

            亚洲第一极品精品无码久久| 亚洲v国产v天堂a无码久久| 亚洲欧美另类日本久久国产真实乱对白 | 精品久久久久久久中文字幕| 一本一道久久a久久精品综合| 亚洲国产精品狼友中文久久久| 性做久久久久久久久老女人| 97精品伊人久久大香线蕉| 国产精品久久一区二区三区| 亚洲精品国产综合久久一线| 狠狠综合久久AV一区二区三区| 亚洲国产成人久久精品99| 熟妇人妻久久中文字幕| 久久久精品国产亚洲成人满18免费网站 | 亚洲伊人久久综合影院| 久久国产高潮流白浆免费观看| 伊人久久亚洲综合影院| 国产Av激情久久无码天堂| 伊人久久大香线蕉av不变影院| 精品午夜久久福利大片| 国产亚洲综合久久系列| 亚洲国产一成久久精品国产成人综合 | 久久久国产精华液| 日本久久久久久久久久| 97久久超碰成人精品网站| 国产精品99久久久精品无码 | 亚洲精品国产自在久久| A级毛片无码久久精品免费| 99久久精品日本一区二区免费| 污污内射久久一区二区欧美日韩 | 久久久网中文字幕| 亚洲а∨天堂久久精品| 久久久久国产亚洲AV麻豆| 草草久久久无码国产专区| 精品久久久久久成人AV| 久久亚洲国产成人精品性色| 久久久久亚洲av无码专区| 久久久久精品国产亚洲AV无码| 日本WV一本一道久久香蕉| 天天影视色香欲综合久久| 亚洲?V乱码久久精品蜜桃|