• <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 閱讀(330) 評論(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品| 久久久精品国产免大香伊| 国产精品久久久久无码av| 亚洲精品tv久久久久| 亚洲日本va中文字幕久久| 国产福利电影一区二区三区久久久久成人精品综合 | 精品久久久久久国产三级| 久久精品亚洲精品国产欧美| 亚洲国产成人精品久久久国产成人一区二区三区综 | 国产精品久久久久久| 久久久久久国产a免费观看黄色大片 | 色综合久久久久综合99| 色综合久久无码五十路人妻| 久久久噜噜噜久久中文字幕色伊伊 | 久久久久一区二区三区| 久久婷婷色香五月综合激情| 久久99国产精品二区不卡| 综合久久精品色| 久久se精品一区精品二区国产| 丰满少妇高潮惨叫久久久| 欧洲人妻丰满av无码久久不卡| 欧美久久一级内射wwwwww.| 久久精品国产亚洲网站| 久久夜色精品国产噜噜麻豆| 2021久久精品免费观看| 综合久久给合久久狠狠狠97色 | 国产91色综合久久免费| 久久亚洲春色中文字幕久久久| 日韩欧美亚洲综合久久影院Ds| 99久久精品免费观看国产| 久久99精品国产99久久| 久久亚洲私人国产精品vA| 久久久噜噜噜久久熟女AA片 | 久久久久久久久无码精品亚洲日韩| 久久综合九色综合网站| 欧美亚洲国产精品久久久久| 一本色道久久88综合日韩精品 |