ProgrammingHardTCS NQT · Infosys

char *names[] = {"ab", "cde", "f"}; What is strlen(names[0]) * strlen(names[1]) + strlen(names[2])?

  1. A. 7
  2. B. 8
  3. C. 14
  4. D. 18

Correct answer: A. 7

strlen excludes the terminator and * binds tighter than +, so 2 * 3 + 1 = 7. 8 reads it as 2 * (3 + 1), 14 counts each '\0' as sizeof would (3 * 4 + 2), and 18 makes both mistakes.

More C Programming questions

Exams that ask this topic