Is using strlen() in the loop condition slower than just checking for the null character?

前端 未结 8 779
鱼传尺愫
鱼传尺愫 2020-12-07 00:39

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<

8条回答
  •  借酒劲吻你
    2020-12-07 01:28

    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.

提交回复
热议问题