How to calculate the length of a string array in the C language?

In C language, the length of a string array can be calculated using the strlen() function, which is declared in the header file. This function takes a string as a parameter and returns the length of that string, which is the number of characters (excluding the trailing ‘\0’ character). Here is an example code:

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

int main() {
    char str[] = "Hello, World!";
    int length = strlen(str);
    printf("Length of string: %d\n", length);
    return 0;
}

The output is: String length: 13.

bannerAds