In C, a string is a character array terminated with a special character '\0'
(ASCII: 0
).
char c[]={1,2,3,4,5};
is a character array.
To make it a string, give last value as 0
, i.e. char c[]={1,2,3,4,5,0};
or better char c[]={1,2,3,4,5, '\0'};
Now your strlen
didn't work because, it finds the end of a string by searching for the '\0'
terminator, which you didn't gave in your array.
It keeps on searching for '\0'
(and causes access of array element out of bounds, which is an undefined behavior, and sometimes very bad). It finds it (by luck) at the 19th character hence returns that result.