I have read that use of strlen is more expensive than such testing like this:
strlen
We have a string x 100 characters long.
x
I think that<
I guess the compiler could optimize (check Gregory Pakosz comment) your first for loop so that you would be like this:
int len = strlen(x); for (int i = 0; i < len; i++)
Which is still O(n).
O(n)
Anyway, I think your second for loop will be faster.
for