c increment & decrement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nandadulal
    New Member
    • Jun 2010
    • 8

    #1

    c increment & decrement

    sir,

    I am a new user of c language .plz. explain me the what will be the output of this code and why?

    int i=1;
    {
    printf("%d%d%d% d",++i,i++,--i,i--);
    }
    actually I understand ++i or i++ but when using with 2 or 4 variables i am being confused.
    plz. explain in details the output of this program.
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    It's undefined because several increments/decrements on i variable happens before the next sequence point. The generated code may change the value of 'i' after calculating all parameters' values, resulting in output 2101, or change it after each parameter value is calculated (2222, if they are evaluated left to right)

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Wasn't this question already answered yesterday in your other post?

      Comment

      Working...