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<
Of course the first one will take longer than the second. They don't actually do the same thing at all--the first one is calculating the length of the string each time; the second one is (effectively) doing it only once.
The first version is equivalent to this:
for (int i=0; x[i] != 0; i++)
for (int j=0; j
Maybe you meant to say "is it more efficient to call a library strlen() than to implement my own?" The answer to that is, of course, "it depends". Your compiler may have intrinsic versions of strlen() that are optimized beyond what you would expect from source, you may be on a platform on which function calls are expensive (rare nowadays), etc.
The only answer that's both general and correct is "profile and find out".