In C the strcpy
function is used to copy a source into a destination string.
But when I use a destination char
array of size 1 the strcpy
correctly copies the source into the destination. But it also changes the source char
array. I want to understand how this works in C.
I have done some research on how to correctly use strcpy
in a program but all of them uses destination size more than 1. I did the program using destination size equal to 1. That's where the problem is.
char a[] = "String ABC";
char b[1];
strcpy(b, a);
int i;
// printf("%c\n", *(&(a[0])-1));
printf("%s\n",a);
printf("%s\n",b);
I expect the output to be
String ABC
String ABC
but the output I get is
tring ABC
String ABC