ProgrammingVery hard

char buf[] = "ab"; buf[2] = 'c'; printf("%zu", sizeof buf); What is printed?

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

Correct answer: D. 3

buf is initialised with three bytes from the literal. Writing buf[2] changes only the terminator, which keeps the size at three bytes.

More C Programming questions

Exams that ask this topic