c++ length of char array

To find the length of a char array in C++, you can use the strlen() function from the C standard library. Here's an example of how to use it:

#include <cstring>

int main() {
    char arr[] = "Hello, World!";
    int length = strlen(arr);
    return 0;
}

In this example, we include the <cstring> header, which provides the declaration for the strlen() function. We declare a char array called arr and initialize it with the string "Hello, World!". Then, we use the strlen() function to calculate the length of the array and assign it to the variable length.

The strlen() function takes a const char* argument, which is a pointer to the first element of the array. It returns the number of characters in the array, excluding the null terminator character ('\0') at the end of the string.

It's important to note that strlen() only works with null-terminated strings, so your char array must be properly null-terminated for strlen() to give the correct result.