🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: String Handling in C: all 15 questions

Quiz: String Handling in C · Question 2 of 15

What is wrong with char s = "hello"; s[0] = 'H';?

What is wrong with char *s = "hello"; s[0] = 'H';?

  1. A.Nothing — it prints Hello
  2. B.It changes a string literal, which is undefined behaviour and usually crashes
  3. C.It does not compile in any compiler
  4. D.s[0] is the '\0' character
Answer & explanation

Correct answer: It changes a string literal, which is undefined behaviour and usually crashes

String literals usually live in read-only memory. Use char s[] = "hello"; to get a copy you can change.

Can you get the rest right without peeking?

Take the timed Quiz: String Handling in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →