Skip to main content

Define and write syntax of strlen()

Short answer

strlen() from <string.h> returns the number of characters in a string, excluding the terminating null character. Its syntax is: size_t strlen(const char *str);

Define and write syntax of strlen().

strlen() is a library function of <string.h> that returns the number of characters in a string, not counting the terminating null character '\0'.

Syntax: size_t strlen(const char *str);

Example: strlen("Nepal") returns 5.

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

int main(void)
{
    char s[] = "Nepal";
    size_t n = strlen(s);
    printf("Length of \"%s\" = %zu\n", s, n);
    return 0;
}

Output: Length of "Nepal" = 5

✓ Answer checked by Claude Opus 5.5 (high effort)

All Computer Programming chapter 7 questions →