Which method is better for incrementing and traversing in a loop in C

Don't worry about it. Your compiler will make this optimization if necessary.

For example, clang 10 unrolls this completely and uses vector instructions to do multiple at once.


As @JeremyRoman stated compiler will be better than the humans optimizing the code.

But you may make its work easier or tougher. In your example the second way prevents gcc from unrolling the loops.

So make it simple, do not try to premature micro optimize your code as result might be right opposite than expected

https://godbolt.org/z/jYcLpT

Tags:

C