Which declaration creates a character array capable of storing the string "CAT" including its null character?
Options
- A. char s[3] = "CAT";
- B. char s[4] = "CAT";
- C. char s[2] = "CAT";
- D. More than one of the above
- E. None of the above
Quiz Practice:
B. char s[4] = "CAT";
Answer: (B) char s[4] = "CAT";
A C-style string is terminated by a special null character, written as ' '.
The string "CAT" contains three visible characters:
C, A, T
One additional position is required for the null character.
Therefore, the required size is:
3 + 1 = 4
Hence, char s[4] = "CAT"; is correct.