ft_strlen

Subject

STRLEN(3) (simplified)

NAME
    strlen -- find length of string
SYNOPSIS
    size_t(const char *s);
DESCRIPTION
    The strlen() function computes the length of the string s.
RETURN VALUES
    The strlen() function returns the number of characters that precede the terminating NUL character.

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

ft_strlen

Last updated

Was this helpful?