Increment and decrement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aki1594
    New Member
    • Feb 2016
    • 1

    Increment and decrement

    Code:
    #include<stdio.h>
    main()
    {
    int i=5;
    printf("%d %d %d %d %d \n",i,i++,++i,i++,i);
    }
    In the TurboC compiler the output is
    8 7 7 5 5
    In the GCC compiler the output is
    8 7 8 5 8

    why the difference?
  • hpmachining
    New Member
    • Oct 2015
    • 15

    #2
    What you have is undefined behavior. The order in which function arguments are evaluated is unspecified in the standard, so how they are evaluated is compiler specific. Here is a link to Kernigan & Ritchie. See chapter 2.12, (specifically page 49) for an example similar to yours.

    Comment

    Working...