C String Length: Using strlen()

In C language, the length of a string can be obtained using the strlen() function. This function is declared in the string.h header file with the following prototype:

size_t strlen(const char *str);

str is the string to calculate the length of, and the return value is the length of the string (excluding the terminating null character \0).

Example of use:

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

int main() {
    char str[] = "Hello, World!";
    size_t len = strlen(str);
    printf("Length: %zu\n", len);
    return 0;
}

The output result is:

Length: 13
bannerAds