There is a terminator at the end of the string in C, which takes up a position, so when you represent a string in a character array, its actual length is declared length-1, so be aware that the array is out of bounds during use.
1#include <stdio.h>2#include <string.h>3 4 intMain ()5 {6 Charname[8] ="Itcasasa";//error C2117: ' Itcasasa ': array bounds overflow7 CharName2[] = {'o','k'};8printf"%s\n", name);9 Ten return 0; One}Using strlen to calculate the length of a string is his actual length, that is, the length after which it is removed.
#include <stdio.h><string.h>int main () { char' 123\0"; printf ("%d\n", strlen (str)); // Output 3 return 0 ;}
Be sure to add a terminator to the string when using a character array, or you will get unexpected results. The storage of strings in memory is stored sequentially and is addressed from the big end, and the output of the string is stopped after the Terminator is encountered.
C language String