Because
char *test = "word";
is not the same as
char test[] = "word";
The first one is string literal it MUST not be changed - changing it causes undefined behavior (as they are immutable).
The second one is a standard (mutable) array of char
s.
By the way, the first one must be (thanks to @ouah and @dasblinkenlight - didn't know, that there's a difference in this case)const char*
, not char*
(and this will even solve the issue - you'll get compile time error)