Take the 32-bit system as an example.
1. Definition and initialization
Character array: char c[10];
String: char s[] = "Hello";
The definition and initialization of a character array can be together or separate:
Char c[10] = "Qwer"; Or
Char c[10];
C[0] = ' Q '; C[1] = ' W '; c[2] = ' e '; C[3] = ' R ';
Can't do this: c = "Qwer"
When initializing, be aware of the size of the array, while preserving the location of the.
When you print a character array with printf, you must have a/s in the array, or it will cause the print to cross.
The definition and initialization of a string cannot be separated, but the specified character can be modified, as
Char s[] = "Hello"; S[1] = ' o ';
2. SizeOf and Strlen
sizeof (c) = 10; is the actual array size
sizeof (s) = 6; Size is the number of characters +1 (1 is hide ' n ')
Strlen does not contain a:
Char c[10] = "Wwer"; Strlen (c) = 4;
Char s[] = "Helloz"; strlen (s) = 6;
3. References
Both are quoted in the same way, in two ways: by means of subscripts or pointers, such as:
Character array: c[1] = ' R ' or * (c + 1) = ' R '
String: s[1] = ' R ' or * (s + 1) = ' R '
4. String related operation function
There are mainly the following, which are basically defined in string.h. Linux system you can use the man command to see the use of each function. Such as:
[Email protected]:~/work/code/ctest$ man str
Strace strchr strcpy strerror strftime strlen strncpy strpbrk strsignal strtof strtol strtoul strverscmp
strcasecmp strchrnul strcspn strerror_r string strncasecmp strndup strptime strspn strtoimax strtold strtoull strxfrm
Strcasestr strcmp strdup Strfmon strings strncat strndupa strrchr strstr strtok strtoll Strtoumax
strcat strcoll strdupa strfry strip strncmp strnlen strsep strtod strtok_r Strtoq Strtouq
[Email protected]:~/work/code/ctest$ man strlen//view strlen Usage
Character arrays and strings