how to find size of string in c code example

Example 1: string length c

#include <stdio.h>
#include <string.h>
int main()
{
    char a[20]="Program";
    char b[20]={'P','r','o','g','r','a','m','\0'};

    // using the %zu format specifier to print size_t
    printf("Length of string a = %zu \n",strlen(a));
    printf("Length of string b = %zu \n",strlen(b));

    return 0;
}

Example 2: what is size_t in c

/*
The datatype size_t is unsigned integral type.
It represents the size of any object in bytes and is returned by the
sizeof operator.
It can never be negative.
*/

Tags:

Cpp Example