ProgrammingHard

char *a = "xy"; char *b = a; b[0] = 'z'; printf("%s", a); What is printed?

  1. A. zy
  2. B. undefined behaviour, because the literal is not writable
  3. C. xy
  4. D. yz

Correct answer: B. undefined behaviour, because the literal is not writable

b points at the string literal, which cannot be modified. Writing to it is undefined.

More C Programming questions

Exams that ask this topic