Arrays and Strings
Character Arrays
C strings are arrays of characters ending with a null terminator.
Character Arrays
char_arrays.c
#include <stdio.h>
int main(void) {
char word[4] = {'c', 'a', 't', '\0'};
char first = ;
word[0] = first;
printf("word=%s\n", word);
return 0;
}
#include <stdio.h>
int main(void) {
char word[4] = {'c', 'a', 't', '\0'};
char first = ;
word[0] = first;
printf("word=%s\n", word);
return 0;
}
#include <stdio.h>
int main(void) {
char word[4] = {'c', 'a', 't', '\0'};
char first = ;
word[0] = first;
printf("word=%s\n", word);
return 0;
}
null terminator
The `'\0'` character marks where a C string ends.
mutable characters
Changing one array element changes the visible string content.