ProgrammingModerate

char s[] = "abc"; printf("%c", s[strlen(s) - 1]); What is printed?

  1. A. b
  2. B. a
  3. C. d
  4. D. c

Correct answer: D. c

strlen("abc") is 3, so s[3 - 1] = s[2] is the last real character, 'c'; s[3] would be the terminator. 'b' subtracts one too many, and 'd' runs past the string.

More C Programming questions

Exams that ask this topic