Because it target[1]is a pointer to "bbbbbbbbbb", and you are not allowed to change string constants. This behavior is undefined.
This is no different from:
char *x = "bbb";
x[0] = 'a';
I think you can be confusing:
char x[] = "bbb";
x[0] = 'a';
which is valid since it creates an array that you can modify. But what gives you:
char* target[2] = {"cccc","bbbbbbbbbb"};
represents an array of pointers, all of which point to unmodifiable memory.
If you tried:
char t0[] = "cccc";
char t1[] = "bbbbbbbbbb";
char* target[2] = {t0, t1};
strcpy(target[1],src);
You will find that it works, as it target[1]now points to t1which can be changed.
source
share