strlen - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# strlen

From cppreference.com
< c‎ | string‎ | byte

Defined in header `<string.h>` |  |
size_t strlen( const char *str ); |  |

Returns the length of the given byte string.

The null character is excluded from the length.

### [edit] Parameters

str | - | pointer to the null-terminated byte string to be examined

### [edit] Return value

The length of the null-terminated string `str`.

### [edit] Example

Run this code

    #include <string.h>
    #include <stdio.h>

    int main(void)
    {
        const char str[] = "How many characters does this string contain?";

        printf("without null character: %zu\n", strlen(str));
        printf("with null character: %zu\n", sizeof(str));

        return 0;
    }

Output:

    without null character: 45
    with null character: 46

### [edit] See also

C++ documentation for strlen

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/string/byte/strlen&oldid=72212"