The strcpy () function was suddenly used today
So
char* A = "ABCDEFG";
char* B = "GGGG";
strcpy (A, b);
Compile pass, but run unexpectedly directly ended, error;
Why is it?
Because char * A = "ABCDEFG";
"ABCDEFG" This is a const property, then it exists in the static storage area, a pointer to the static store, but cannot change its value
So you can't use the strcpy function
and char a[] = "ABCDF";
Char b[] = "CDs"
strcpy (A, b);
can achieve the desired effect, because
Char a[] = "abcdef"; this "abcdef" is still in the static store, but there will be a copy used to initialize the array a on the stack;
So can be modified!
A lot of knowledge knocking code encountered errors will learn, the above reasons used to know the knowledge point, but still write the wrong code, wrong to think why wrong, and then think of the knowledge points learned;
So write more code!!! Learn from your mistakes.
char* A; char*b strcpy (A, b) error