I have read that use of strlen
is more expensive than such testing like this:
We have a string x
100 characters long.
I think that<
I can suppose that in first variant you find strlen each iteration, while in second variant you don't do that.
Try this to check:
int a = strlen(x);
for (int i = 0; i < a; i++) {...}
If no there's no compilation optimization. Yes because strlen will iterate on every byte of the string every time and the second implementation will do it only once.