C strlen() method

This function calculates the length of the string (not including the null terminator).

Syntax:


strlen(stringName);

Example:


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

int main() {
    char str[] = "My World";
    printf("Length of string: %d", strlen(str));  // Output: 8
    return 0;
}

Output:

8

Note: string.h is a standard header file which is use to string in the function.