Namespaces
Variants
Views
Actions

strlen

From cppreference.com
< c‎ | string‎ | byte
Revision as of 01:29, 27 December 2013 by Satishgoda (Talk | contribs)

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.

Contents

Parameters

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

Return value

The length of the null-terminated string str.

Example

#include <string.h>
#include <stdio.h>
 
int main()
{
    const char str[] = "How many characters contains this string?";
 
    printf("without null character: %d\n", strlen(str));
    printf("with null character: %d\n", sizeof(str));
 
    return 0;
}

Output:

without null character: 41
with null character: 42

See also