• <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 閱讀(317) 評論(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网站| 狼狼综合久久久久综合网| 久久成人精品视频| 久久精品国产精品亚洲人人| 久久嫩草影院免费看夜色| 国产精品美女久久久久久2018| 浪潮AV色综合久久天堂| 久久精品成人免费网站| 色综合久久久久综合99| 久久精品9988| 亚洲国产成人久久综合野外 | 国产成年无码久久久久毛片| 日本一区精品久久久久影院| 久久人人爽人人爽人人av东京热 | 99久久久久| 69SEX久久精品国产麻豆| 亚洲国产另类久久久精品| 看全色黄大色大片免费久久久| 色欲av伊人久久大香线蕉影院| 91久久国产视频| 99久久精品国产麻豆| 97精品依人久久久大香线蕉97 | 久久亚洲av无码精品浪潮| 日韩精品久久久久久免费| 久久久久久一区国产精品| 久久国产高清字幕中文| 久久久久99精品成人片欧美| 久久久精品国产sm调教网站| 亚洲国产精品综合久久一线| 亚洲天堂久久精品| 欧美综合天天夜夜久久| 丰满少妇人妻久久久久久| 久久亚洲精品人成综合网| 精品久久久一二三区| 久久丫精品国产亚洲av| 亚洲精品第一综合99久久 | 99久久精品无码一区二区毛片 | 久久超碰97人人做人人爱| 久久精品免费一区二区| 77777亚洲午夜久久多喷| 久久久亚洲裙底偷窥综合|