An alien variable suddenly in an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HolyDoom Witch
    New Member
    • Oct 2012
    • 34

    #16
    Guess what. This Rabbit made a grave mistake too.

    Now I realize, that only if he used "n" instead of "x", then he would have taken the credit, that also at least 10-20 minutes earlier than it struck me! :D
    _______________ ____________

    Jokes apart. But this was actually a mistake by the author himself, where in an explanation, he used "a", saying something will happen to "a", but in the example he used "b", and now that thing was happening to "b". It took me a FULL TWO DAYS to get past that paragraph! ...till I finally realized that it was not even a mistake, and yet a HUGE one! Let me post that part to you people. He even says in the end 'see? how "b" changes'! (That was the final nail in my coffin! :D)

    A characteristic of this operator is that it can be used both as a prefix and as a suffix. That means that it can be written either before the variable identifier (++a) or after it (a++). Although in simple expressions like a++ or ++a both have exactly the same meaning, in other expressions in which the result of the increase or decrease operation is evaluated as a value in an outer expression they may have an important difference in their meaning: In the case that the increase operator is used as a prefix (++a) the value is increased before the result of the expression is evaluated and therefore the increased value is considered in the outer expression; in case that it is used as a suffix (a++) the value stored in a is increased after being evaluated and therefore the value stored before the increase operation is evaluated in the outer expression. Notice the difference:

    Example 1
    B=3;
    A=++B;
    // A contains 4, B contains 4;

    Example 2
    B=3
    A=B++;
    // A contains 3, B contains 4

    In Example 1, B is increased before its value is copied to A. While in Example 2, the value of B is copied to A and then B is increased.
    See?! I told ya!

    If only he used A=3, then I would not suffer!

    The author wasn't interested in correcting content, even though he had sought emails through a form, regarding content; he wasn't responding (by making amends or replying back). So I had already left writing to him. Though I might add his was the best one I found on the net.

    Enjoy! :D

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #17
      It looks like you are progressing. My experience with C++ is that when it starts to get really complicated a red flag should pop up in your mind with the words WRONG WAY on it.

      Comment

      • HolyDoom Witch
        New Member
        • Oct 2012
        • 34

        #18
        Ideally... lest you start believing in the existence of 'ghost' programs!

        (Hey your name is "Weakness For Cats", and not "Weakness Forcats" like I had thought! I am really poor in crosswords like tasks.) (Should use Title Case.)

        Comment

        • HolyDoom Witch
          New Member
          • Oct 2012
          • 34

          #19
          Like I had said, that I should have waited some more, and I am right; I knew I would be. As it becomes clear, the next example was using the same "for" loop with the same variable "n", and also had some amount of explanation for the thing I missed. Though I had seen the code example one glance, and not read the text, thinking it would be of no use! If I had read on, which I always do, in search of similar examples if I did not understand something (but which probably all readers do), then by reading the text if not seeing the code I would remember what my mind was ignoring/ forgetting, due to some clarity also in the given explanation. Though just the code here also this time makes it quite clear. Looks like somehow, I took it easy this time.

          Huff. I don't know why I make well known mistakes. :-/

          Comment

          Working...