c / beginner
Snippet
Strings as Character Arrays
In C, strings are simply arrays of characters ending with a special null character '\0'.
snippet.c
1
2
char greeting[] = "Hello";printf("%s has %lu characters", greeting, strlen(greeting));
Breakdown
1
char greeting[]
Declares an array of characters to hold the string.
2
"Hello"
The compiler automatically adds a hidden '\0' at the end.
3
strlen(greeting)
A function that returns the length of the string (excluding the null terminator).