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

    Join Date
    Oct 2012
    Rep Power

    C Increment Problem

    I guessed how it worked in Visual C++ but didn't understand the operations in case of 1st type output. Help someone!

     #include <stdio.h>
      int main()
            int i=5;
            printf("%d %d %d %d \n",i,i++,++i,i++);
            printf("%d \n",i);
            return 0;
      /* output in g++ and codeblocks
      8 7 8 5
      output in Microsoft Visual C++ 6.0
      6 6 6 5
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    Same test, with a many more compilers

    Now learn about multiple side effects and sequence points

    If you've got multiple side effects on the same object between sequence points, the code is screwed - period.

    You can analyse it all you want, but it is a pointless exercise. You won't learn anything useful that you can apply in any other programming problem.

    Comments on this post

    • Lux Perpetua agrees
    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

IMN logo majestic logo threadwatch logo seochat tools logo