• <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久久免费国产精品| 久久精品aⅴ无码中文字字幕不卡| 区久久AAA片69亚洲| 久久se精品一区精品二区| 精品国产婷婷久久久| 久久精品国产网红主播| 久久99久久无码毛片一区二区| 亚洲精品美女久久久久99| 亚洲狠狠综合久久| 国内精品久久久久影院薰衣草 | 亚洲婷婷国产精品电影人久久| 一本色道久久99一综合| 久久久久国产| 久久国产亚洲精品麻豆| 亚洲综合精品香蕉久久网| 久久综合五月丁香久久激情| 国产日产久久高清欧美一区| 亚洲中文久久精品无码ww16| 久久av免费天堂小草播放| 日本免费久久久久久久网站 | 国产午夜精品久久久久免费视 | 欧美精品久久久久久久自慰| 一本大道久久香蕉成人网| AA级片免费看视频久久| 97r久久精品国产99国产精| 久久人人爽人人爽人人AV东京热| 热99RE久久精品这里都是精品免费 | 久久久久久久久久久免费精品| 久久男人Av资源网站无码软件 | 亚洲AV无码久久精品色欲| 亚洲国产成人久久一区WWW| 久久精品亚洲精品国产欧美| 狠狠色综合网站久久久久久久| 亚洲国产成人久久综合一| 99久久国产主播综合精品| 国产精品成人久久久久三级午夜电影 | 久久亚洲国产成人影院网站| 激情五月综合综合久久69| 国内精品久久久久久麻豆| 99久久精品免费国产大片|