Does C Have Strings?
Direct Answer: No, C does not have a built-in string type. Instead, strings are represented as arrays of characters.
C’s approach to strings, while not immediately intuitive to those coming from languages with dedicated string types, has its own set of strengths and nuances. Understanding how strings are handled in C is crucial for writing correct and efficient code.
The Nature of Strings in C
Representing Text in C
C treats strings as sequences of characters. Critically, these sequences are not inherently distinct from ordinary character arrays. A string in C is simply an array of char that is null-terminated. This means the characters that make up the string are simply stored adjacently in memory, and a special character, the null character (
