#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    Help in post and pre incremet operators


    hello, i am new to this forum.

    i have a confusion in post and pre increment operators. please help me.

    #include<stdio.h>
    int main()
    {
    int d=1,c;
    c= d++ + ++d + ++d;
    printf("%d %d",c,d);
    return 0;
    }

    i get c as 7 and d as 4 .. please explain me how..
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,995
    Rep Power
    481
    The result is undefined. This question was raised then razed muchly in the last two weeks. Read this post.

    or this

    My absolute favorite set of answers to this question.


    Use this sort of google command for other answers:
    site:http://forums.devshed.com/c-programming-42 pre post increment
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Another example of undefined behaviour.

    It is unspecified whether you'll read the answer first on this forum, or on another forum
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0

    thank you and sorry


    thank you all..

    hi salem.. i am extremely sorry about that.. i am in urgent need of answer. so i couldnt hesitate to post in another forum..
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by salem
    Another example of undefined behaviour.

    It is unspecified whether you'll read the answer first on this forum, or on
    very sorry..

IMN logo majestic logo threadwatch logo seochat tools logo