STRLEN()

#include <stdio.h>  // printf
#include <string.h> // strlen

void main (void)
{
    char string_array[] = "This is a string";

    printf("strlen(string_array) is %ld\n", strlen(string_array));
    printf("sizeof(string_array) is %ld\n", sizeof(string_array));
}

 * the strlen function returns the length of the string, in characters (or bytes), not 
   including the terminating NULL byte. The sizeof operator returns the number of bytes
   the array consumes in memory. Ultimately, when working with strings the number of 
   bytes consumed by the array will be one greater than string length as it takes into 
   account the full size of the array to include the terminating NULL byte.

Last updated