Give me a chestnut first:
A string array followed by a string pointer, then using sizeof and strlen to see the output.
Char stra[] = "2017-7-19";
Char *strb = "23333";
cout <<sizeof (a) <<ends<<sizeof (b) <<endl;
Above output 10 4;
A string array length of 10, because it contains the Terminator ' \ n ';
b The length of the string pointer is 4, (32-bit machine pointer length is 4, the other type is the same, no matter how long the string to point)
If you want to test the last one is not, loop to the last one and make a judgment is not "."
cout <<strlen (a) <<ends<<strlen (b) <<endl; "Note that the strlen parameter here is the type of char"
Above output 9 5;
Strlen actually returns the length of the string, which is the length of the data saved in the original string array/string pointer.
C + + talking about the difference between strlen and sizeof