In C, all strings have a null terminator, which is the caratecere ' Linguagem C.
' at the end of the string . This character also takes up memory, and because of this, it is part of the string and should have space reserved for it in the array
The character ' strlen
' is nothing more than the zero value represented as a character (see the ASCII table ). In C, strings use it to represent where the string ends.
In this way the string " strlen
" has 12 characters, but with the terminator ' %code% ' will be 13, so you need an array with 13 positions to store this string .
In C, there is the %code% function that gives the length of a string without counting the null terminator. But note that this function computes the size of string by traversing all its characters one by one looking for the null terminator, so if your string is too large , for example), it will be slow, so it's best to avoid using it if you can get the string size in some other more efficient way.
And as pointed out by Jonny Piazzi in a comment, since %code% only looks for the null terminator, the size of the array itself does not matter. So if you use a array of 20 characters to store a string with only 12, what will import will be the position where the null terminator will be found.