On this page
  1. strlen
  2. Include
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

strlen

Prev: memchr | Up: string.h | Next: strcmp
Rel: string.h, stdlib.h & string.h Guide
Ref: cppreference — strlen
Tags: #public #prog #c #stdlib #string #tier/core


Include

#include <string.h>

Signature & Overview

size_t strlen(const char *str);

Returns the byte length of a NUL-terminated string in $O(n)$, excluding '\0'.

Notes & Pitfalls

Example

#include <assert.h>
#include <string.h>

int main(void) {
    const char *s = "hello";
    size_t len = strlen(s);
    assert(len == 5);
}

Linked from

Related notes