ProgrammingHard

for (i = 0; i < strlen(s); i++) process(s[i]); with a string of length 5. How many times is strlen called?

  1. A. 5
  2. B. 10
  3. C. 6
  4. D. 1

Correct answer: C. 6

The condition is tested 6 times (5 successful tests and one failing), and strlen runs at each test. Storing the length once avoids this.

More C Programming questions

Exams that ask this topic