I am executing this piece of code.
#include<stdio.h>
#include<string.h>
int main()
{
char str1[]="himanshusaini";
char str2[5];
strcpy(str2,str1);
printf("str1=%s\n str2=%s\n",str1,str2);
return;
}
=========== Output is
str1=shusaini str2=himanshusaini
How the strcpy is working here, why the str1 is getting modified while str1 is the source string, and str2 is destination. On the other hand output of the str2 is full source string while size of str2 is only 5 byte.
Please assist me What is exactly happening here.