diff bt postfix and prefix unary

Discussion in 'C Programming' started by shan, Oct 10, 2005.

  1. shan

    shan Guest

    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.
     
    shan, Oct 10, 2005
    #1
    1. Advertising

  2. shan

    Mike Wahler Guest

    "shan" <> wrote in message
    news:...
    > 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.


    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
     
    Mike Wahler, Oct 10, 2005
    #2
    1. Advertising

  3. shan

    Chris Dollin Guest

    shan wrote:

    > 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 .


    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`.

    > plz give me an example program with output.


    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?"
     
    Chris Dollin, Oct 10, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sergey
    Replies:
    6
    Views:
    2,953
    Victor Bazarov
    Apr 1, 2005
  2. SpOiLeR
    Replies:
    10
    Views:
    854
    SpOiLeR
    Oct 19, 2005
  3. Xah Lee
    Replies:
    30
    Views:
    1,850
    Peter J. Holzer
    Jun 16, 2007
  4. Xah Lee
    Replies:
    30
    Views:
    1,306
    Peter J. Holzer
    Jun 16, 2007
  5. Xah Lee
    Replies:
    32
    Views:
    649
Loading...

Share This Page