When the array size is defined:
sizeof is an operator that represents the amount of space allocated at compile time, that is, the size of the array definition, char t[20] = "SFA". sizeof:20; Strlen:3.
When the array size is undefined :
sizeof is determined based on the actual number of digits, Note that the string hidden in the .
Char s[] = "a\128\\\tcb\xdg\n";
sizeof calculates the size of S, 11 bits: a \12 8 \ t \ c b \xd g \ n
strlen when calculating the size of S, 10 bits:strlen ends when calculating the string length, but the size calculation does not include
Char a[] = "a0\0a0\0";
sizeof (a) size is 7, i.e.: a 0/a 0
Strlen (a) size is 2
Char s[] = "a\128\\\tcb\xdg\n"; Print character array s: escape character:
Any character represented by the \yyy:1~3 Octet, where the range of Y is 0~7
\xyy:1~2 a hexadecimal representation of any character, where the range of Y is 0~f
for (int0sizeof(s); i++) { printf ("%c", S[i]);} A8\ CBG
\12:2 bit octal number, decimal 10, control character LF, for line break, to start at the next line
\ \: Indicates \
\ t: Represents a horizontal tab, which is a tab
\xd:1 digit hexadecimal number, decimal 13, control character CR, indicates carriage return
Note the octal and hexadecimal questions of the translation word:
Char s[] = "A\12345b\x1221g\xay";
Octal up to 3 bits, that is, \123, when the octal number is converted to decimal than the ASCII Code table maximum of 127, is a garbled.
Hexadecimal is selected up to two bits, but the last 2 bits of the integer after intercepting \x are processed, the preceding bits are discarded, that is, the truncation, that is, the discard 12, the hexadecimal \x21, the decimal 33 represents!
So in the length calculation:
sizeof is 10 bits, namely: a \123 4 5 b \x21 g \xa y
Strlen is 9 bits, namely: a \123 4 5 b \x21 g \xa y
Transfer characters----sizeof & strlen