ProgrammingHardTCS NQT · Infosys

char msg[] = "abc"; printf("%c", msg[msg[0] - 'a' + 1]); What is printed?

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

Correct answer: B. b

msg[0] is 'a', so 'a' - 'a' + 1 is 1, and msg[1] is 'b'. The character constants are used as integers, which is well defined.

More C Programming questions

Exams that ask this topic