This might be trivial and I hope someone could explain this. Why strlen is giving me larger number than this real size of char array instead of 4: Here is my code:
#include <stdio.h>
#include <string.h>
int main ()
{
char szInput[4];
szInput [0] = '1';
szInput [1] = '1';
szInput [2] = '1';
szInput [3] = '1';
printf ("The sentence entered is %u characters long.\n",(unsigned)strlen(szInput));
return 0;
}
I thought I should be getting 4 as the output but I am getting 6.
The sentence entered is 6 characters long.