postfix and prefix

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • puzzlecracker

    postfix and prefix

    How can we implement operator ++ as postfix in prefix?

    thanks
  • zacks@construction-imaging.com

    #2
    Re: postfix and prefix

    On Oct 6, 2:01 pm, puzzlecracker <ironsel2...@gm ail.comwrote:
    How can we implement operator ++ as postfix in prefix?
    >
    thanks
    Not really sure what you are asking, but the ++ operator can be
    applied in front of a variable or behind it. If in front, the value is
    incremented before the value is "looked at". If after, the value isn't
    incremented until after it is "looked at".

    Comment

    • Arto Viitanen

      #3
      Re: postfix and prefix

      puzzlecracker kirjoitti:
      How can we implement operator ++ as postfix in prefix?
      >
      thanks
      In C

      int a=10;
      printf("%d\n", ++a);

      prints 11 and

      int a=10;
      printf("%d\n",a ++);

      prints 10

      (and on both cases, a is 11 after the code).

      The first ++ is called prefix and the second postfix.

      On C++ if you like to add ++ to your own classes, you have to implement
      separate operators for postfix and prefix ++ operators. However, this
      article : http://devhawk.net/2003/07/10/Operat...ding+In+C.aspx
      claims that for C# you have to implement only one operator, the compiler
      handles the difference.

      --
      Arto Viitanen

      Comment

      Working...