By convention C strings are 'null-terminated'. That means that there's an extra byte at the end with the value of zero (0x00
). Any function that does something with a string (like printf
) will consider a string to end when it finds null. This also means that if your string is not null terminated, it will keep going until it finds a null character, which can produce some interesting results!
As the first item in your array is 0x00, it will be considered to be length zero (no characters).
If you defined your string to be:
char a[7]={0xdc,0x01,0x04,0x00};
e.g. null-terminated
then you can use strlen
to measure the length of the string stored in the array.
sizeof
measures the size of a type. It is not what you want. Also remember that the string in an array may be shorter than the size of the array.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…