Prefix and Postfix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NongThin
    New Member
    • Dec 2013
    • 1

    Prefix and Postfix

    #include<stdio. h>
    #include<conio. h>
    #include<limits .h>
    int main()
    {
    int i,j=5;
    clrscr();
    i=++j;
    printf("The value of i=%i and J=%i\n\n",i,j);
    j=5;
    i=j++;
    printf("The Value of j=%i and i=%i",j,i);
    getch();
    return 0;
    }
    /*Please teach me th operating of this ++ and --*/
    /*The value come so different what I have imaging so...(;_;)*/
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    OK. If i and j are 5.

    Then

    i = ++j;

    makes i 6. This is prefix increment: increment first then use the value.

    However,

    i = j++;

    makes i 5. This is postfix: Use the value then increment.

    Comment

    Working...