String
#include <string.h>
Character Array
In C, there is no built-in string
type. As an alternative, we use character arrays to represent a string:
Although the length of Danny
is 5
, there is an invisible character '\0'
at the end, which C uses to indicate the end of the character array. Hence, the size of name
array is actually 6
.
Just like normal arrays, you can initialize char arrays using {}
(note that here, we have to a xx'\0'
character by ourselves):
Then you can print the character array using a loop:
strlen()
TODO:
strcpy()
TODO:
strcmp()
TODO:
Last updated