ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

What is printed?
char s[] = "Hello";
s[0] = 'J';
s[4] = '\0';
printf("%s %zu", s, sizeof(s));
  1. A. Jello 6
  2. B. Jell 5
  3. C. Jello 5
  4. D. Jell 6

Correct answer: D. Jell 6

s is a modifiable array of 6 chars (5 letters + '\0'). Changing s[0] gives "Jello", and writing '\0' at index 4 ends the string early, so %s prints "Jell". sizeof(s) is the array size fixed at declaration, still 6; only strlen would change.

More C Programming questions

Exams that ask this topic