strlen() function in C is used to calculate the length of the given string. It counts the number of characters present in a String excluding the null character ‘\0‘.
The strlen() function is defined in the header file string.h
. It takes one argument that is the string name and written as follows:
strlen(string_name);
C Program for strlen() function
1 2 3 4 5 6 7 8 9 10 11 | #include <stdio.h> #include <string.h> int main() { char str[20] = "Simple2Code"; printf("Length of a String str: %zu", strlen(str)); return 0; } |
Output:
Length of a String str: 11