The strlen()
function takes a string as an argument and returns its length. The returned value is of type size_t
(the unsigned integer type).
It is defined in the <string.h> header file.
The strlen() function calculates the length of a given string.
#include #include 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; }
Output:
Length of string a = 7 Length of string b = 7
Note that the strlen()
function doesn't count the null character \0
while calculating the length.
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.