Ad Code

Responsive Advertisement

strlen() function in C with Example

 String Length: strlen() function in C


The strlen() function returns the length of the given string. It doesn't count null character '\0'.

Here's the syntax for the strlen() function::
c
size_t strlen(const char *str);

const char *str: This is a pointer to the null-terminated string whose length is to be determined.


The function returns a size_t value representing the length of the string.

Example :
c
#include <stdio.h> #
include <string.h>
int main()
const char *myString = "Hello, World!"
size_t length = strlen(myString); 
printf("The length of the string is: %zu\n", length); 
return 0
}

In this example, the strlen() function is used to find the length of the string "Hello, World!" stored in the myString variable. The length is then printed using printf(). Remember that the length returned by strlen() does not include the null-terminating character ('\0').

Post a Comment

0 Comments