multiple '++' working in variables, and pointers

后端 未结 4 659
悲&欢浪女
悲&欢浪女 2021-01-25 20:25

This is what I think the ++ operator does

  1. a++; // a+=1 after calculating this line
  2. ++a; // a+=1 before calcuating this lin
4条回答
  •  情话喂你
    2021-01-25 21:08

    It's not "per line", it's "per sequence-point" which is similar to "per expression" that the result from pre- and post- increment seem to occur.

    In fact, the increment always occurs immediately. The only variation is whether the value of the term will result in the initial or afterward value.

    To fully understand that C is not line-oriented, please refer to the standard and read the parts about "sequence points."

    Lines which begin with '#' are pre-processor input. The pre-processor for C is line-oriented, but, otherwise, C itself considers the line-break characters the same as any other white space such as tab or space.

提交回复
热议问题