How to determine the length of a C language string?

In C language, the length of a string can be calculated using the standard library function strlen. The prototype of the strlen function is as follows:

size_t strlen(const char *str);

The pointer str is pointing to a string that ends with null, the return value is the length of the string, excluding the null character.

Here is an example code for calculating the length of a string.

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

int main() {
    char str[] = "Hello, World!";
    size_t len = strlen(str);
    printf("字符串的长度是:%zu\n", len);
    return 0;
}

The output is:
The length of the string is 13.

bannerAds