In C, accessing my array index is faster or accessing by pointer is faster?

前端 未结 8 1057
忘了有多久
忘了有多久 2021-01-04 06:33

In C, accessing an array index is faster or accessing by pointer is faster? By faster I mean, which one would take less clock cycle. The array is not an constant array.

8条回答
  •  醉话见心
    2021-01-04 07:07

    Simple index operations compile to the same machine code on every compiler I've ever touched. By index is usually recommended for readability.

    More complex cases that involve different logic for pointer access vs array indexing need to be examined on a case-by-case basis. If you are in doubt, profile your code - as always.

提交回复
热议问题