If I declare a string with 10 elements like this:
char s[10];
then does the ‘\0’at the end occupy the 10th place or the 11th? Basically my question is that do we get 1 element less in the string?
And if I use the strlen() function to find this string’s length, will the return value be inclusive of the null? I.e if the string is “boy”, will the function give me 3 or 4?
There is no 11th place, ie, yes, that is one less element to use.
Don’t put a string longer than 9 chars in there.
Strlen()does not include the null terminator.Eg:
sis an array of 6 chars, but thestrlen()ofsis 5.