13.Comparison of sizeof and strlen

1.sizeof finds the size of the space occupied by the data type (not affected by the content stored in it), while strlen finds the length of the string.

Insert image description here
2. The parameter of sizeof can be a variable or a data type, and the parameter of strlen can only be a string ending with "\0".
Insert image description here
3. The compiler calculates the size of sizeof during compilation, but strlen can only calculate the string length while the program is running.
4. In the sub-function, ziseof will treat the character array passed in from the main function as a pointer.

Insert image description here
5. For character arrays, '\0' also occupies a node in sizeof calculation, but does not count in strlen, because strlen is used to calculate the length of the string, and the end mark is not counted.
Insert image description here

Reference blog: https://blog.csdn.net/shimadear/article/details/83306539

Guess you like

Origin blog.csdn.net/qq_43847153/article/details/126821484