</>EmbeddedInterview

Implement strlen().

Easy"Coding: Memory & String Functions"
#include <stddef.h>

size_t my_strlen(const char *s)
{
    const char *p = s;
    while (*p) p++;
    return (size_t)(p - s);          /* pointer difference = number of chars before '\0' */
}

Points to mention: returns size_t; does not count the terminator; undefined if s is NULL or not terminated (the library does not check NULL either). For a bounded version use strnlen(s, max). Library implementations read a word at a time using the "has zero byte" trick after aligning the pointer.