C: What is the difference between ++i and i++?

前端 未结 21 2069
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 06:04

In C, what is the difference between using ++i and i++, and which should be used in the incrementation block of a for loop?

21条回答
  •  灰色年华
    2020-11-21 06:05

    The following C code fragment illustrates the difference between the pre and post increment and decrement operators:

    int  i;
    int  j;
    

    Increment operators:

    i = 1;
    j = ++i;    // i is now 2, j is also 2
    j = i++;    // i is now 3, j is 2
    

提交回复
热议问题