I am trying to understand when I specify the value of "strx" more than 10 characters, it always leads to strcmp showing up the value of -1 whereas when I specify value of strx less than 10 characters then strcmp shows the correct value of 0.
My specific question: if we specify the value of strx more than the size of str1, why does the strcmp gives up the false result of -1?
PS: I tried to print the str1 and strx after the copy and it shows same output.
#include <stdio.h>
#include <string.h>
int main()
{
char strx[]="123456789101112";
char str1[10];
strcpy(str1,strx);
int ret;
ret = strcmp(str1,strx);
printf("%d\n", ret);
if(ret == 0)
{
printf("Intact. Try Again\n");
printf("Str1 = %s\n",str1);
}
else
{
printf("Overflow successful\n");
}
return 0;
}