what is difference between ++i and i+=1 from any point of view

前端 未结 7 575
一个人的身影
一个人的身影 2021-01-03 06:10

This is a question from kn king\'s c programming : a modern approach. I can\'t understand the solution given by him:-

The expression ++i is equivalent to (i          


        
7条回答
  •  余生分开走
    2021-01-03 06:37

    One difference that has not been brought up so far is readability of code. A large part of loops use increment by one and common practice is to use i++/++i when moving to the next element / incrementing an index by 1.

    Typically i+= is used in these cases only when the increment is something other than 1. Using this for the normal increment will not be dangerous but cause a slight bump in the understanding and make the code look unusual.

提交回复
热议问题