Strlen sizeof strcat strcpy, strcatstrcpy
Strlen (p ):
- Calculate the length of p pointing to the string (starting from the current position of p), excluding the ending character '\ 0 ';
- P can be declared as char * p or char p []. Both forms of strlen can be correctly calculated.
Sizeof (p ):
- Sizeof is an operator, a non-function, and its value is determined during the compilation period. Therefore, when p is declared as a Type pointer, sizeof cannot determine the size of the content to be pointed to during compilation, therefore, the returned value is the size of the pointer type;
When p is declared as an array of a type, sizeof can determine the size of the content to be pointed to during compilation. Therefore, the returned value is the size of the array;
Strcat (p1, p2) and strcpy (p1, p2)
Similarities:
- P1 must be a variable pointer to the content, such as char p1 []
- When the character currently pointed to by p1 is the ending character ('\ 0'), it is connected directly with the p2 content or overwritten at the current position of p1 and after
Differences:
- When the character currently pointed to by p1 is not the ending character ('\ 0'), strcat automatically connects the content of p2 at and after the ending character; strcpy directly uses p2 content to overwrite the content currently pointed to by p1.