What are convincing examples where pointer arithmetic is preferable to array subscripting?

前端 未结 9 642
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 09:23

I\'m preparing some slides for an introductory C class, and I\'m trying to present good examples (and motivation) for using pointer arithmetic over array subscripting.

9条回答
  •  半阙折子戏
    2020-12-30 10:28

    iterating through a 2-dimensional array where the position of a datum does not really matter
    if you dont use pointers, you would have to keep track of two subscripts
    with pointers, you could point to the top of your array, and with a single loop, zip through the whole thing

提交回复
热议问题