Is "\ 0" included at the end of the line?

If I declare a string with 10 elements like this:

char s[10];

then does' \ 0'a end in 10th place or 11th? Basically, my question is that we get 1 element less per line?

And if I use the strlen () function to find this string length, will the return value include a null value? I. If the string is “boy”, will the function give me 3 or 4?

+3
source share
4 answers

There is no 11th place, i.e. Yes, this is one of the less used items.

Do not put a string longer than 9 characters. Strlen()does not include a zero limiter.

For instance:

char s[]="hello"; 

s- an array of 6 characters, but Strlen()of sis 5.

+10

, \0 10- . , 9 . , strlen() .

+2

, . , , . :

char s[] = "This is a test."

- :

char s[10] = "012345678"
printf("%d\n", strlen(s));

, , 9. 10 , .

+2

10 , , , 9 .

strleninstead, it returns only the number of “logical” characters, i.e. he will not consider a null limiter.

+1
source

All Articles