ft_strlen
Subject
Understandable explanation
For this function, the man is pretty self-explanatory on what the function does, but some things are new, we never seen some things before.
The strlen()
function returns the number of characters before the terminating NUL
(\0
) character of the string.
What does this mean ?
If our string is abcde\0
, strlen()
will return 5
.
The string we pass as parameter has the keyword const
before it, this means we can't modify this string inside our function, since it's a constant value.
The returned value of strlen()
is of type size_t
, what is it ? Let me explain.
As said on geeksforgeeks.org, the size_t
data type is a type which is used to represent the size of objects in bytes and is therefore used as the return type by the sizeof
operator. It is guaranteed to be big enough to contain the size of the biggest object the host system can handle. Basically the maximum permissible size is dependent on the compiler; if the compiler is 32 bit then it is simply a typedef (i.e., alias) for unsigned int
but if the compiler is 64 bit then it would be a typedef for unsigned long long
. The size_t
data type is never negative.
Hints
Commented solution
Come on ! You wrote this function like a hundred times during the Piscine, you really need to see the code ?
Last updated