1. Welcome Guest! In order to create a new topic or reply to an existing one, you must register first. It is easy and free. Click here to sign up now!.
    Dismiss Notice

i = 4, i++ + i should return 9, but returns 8

Discussion in 'Microsoft News' started by NewsBot, Mar 28, 2008.

  1. NewsBot

    NewsBot I Got News

    Joined:
    Feb 8, 2006
    Messages:
    1,813
    Operating System:
    Windows Vista Home Premium
    My C/C++ professor mentioned in class that many compilers cannot properly evaluate the expression i++ + i and some permutations of it, so I decided to test that out in Visual Studio with a small program:

    #include

    int main ( void )
    {

    *** int i = 4;

    *** printf("%i", i++ + i);

    *** return 0;

    }

    It returns 8. It should return 9. Why does it return 8?




     

Share This Page