how many times will strlen() be called in this for loop?

后端 未结 6 705
渐次进展
渐次进展 2020-12-03 14:46

Will the strlen() function below get called just once (with the value stored for further comparisons); or is it going to be called every time the comparison is performed?

6条回答
  •  失恋的感觉
    2020-12-03 15:10

    I'll sometimes code that as ...

    for (int i = 0, n = strlen(word); i < n; ++i) { /* do stuff */ }
    

    ... so that strlen is only called once (to improve performance).

提交回复
热议问题