diff bt postfix and prefix unary

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

    diff bt postfix and prefix unary

    Hi to everybody,

    I am begginer in C programming language.
    My simple doubt is the difference between postfix & prefix unary
    operator plus.
    (i.e) i++ and ++i .

    plz give me an example program with output.

  • Mike Wahler

    #2
    Re: diff bt postfix and prefix unary

    "shan" <srishankar18@g mail.com> wrote in message
    news:1128954852 .019856.221250@ g49g2000cwa.goo glegroups.com.. .[color=blue]
    > Hi to everybody,
    >
    > I am begginer in C programming language.
    > My simple doubt is the difference between postfix & prefix unary
    > operator plus.
    > (i.e) i++ and ++i .
    >
    > plz give me an example program with output.[/color]

    The value of a prefix increment expression is the
    value after the increment.

    The value of a postfix increment expression is the
    value before the increment.

    #include <stdio.h>

    int main()
    {
    int pre = 1;
    int post = 1;


    /* prints 2 1 */
    printf("++pre == %d post++ == %d\n", ++pre, post++);


    /* prints 2 2 */
    printf(" pre == %d post == %d\n", pre, post);
    return 0;
    }

    This is very fundamental C. Which texbook(s) are you
    reading which don't explain this?

    -Mike


    Comment

    • Chris Dollin

      #3
      Re: diff bt postfix and prefix unary

      shan wrote:
      [color=blue]
      > Hi to everybody,
      >
      > I am begginer in C programming language.
      > My simple doubt is the difference between postfix & prefix unary
      > operator plus.
      > (i.e) i++ and ++i .[/color]

      This should be explained in any decent introductory C book.

      `i++` returns the current value of `i`. `++i` returns one more than
      the current value of `i`. Both eventually [1] increment `i`.
      [color=blue]
      > plz give me an example program with output.[/color]

      Oh, /please/. /You/ write an example program for this. If you can't,
      you're not ready for the ++ operators yet.

      [1] By the next sequence point. Often a `;`.

      --
      Chris "electric hedgehog" Dollin
      "I know three kinds: hot, cool, and what-time-does-the-tune-start?"

      Comment

      Working...