Bosses for help!!!!!!!!!!!!!!
Bosses for help!!!!!!!!!!!!!!
Why can't a character pointer as strcpy () the first parameter to the
Please look at the source code
char * a="efgh";
Char * c="abcd";
Char [] d="abcd";
//strcpy (c, a);
Strcpy (d, a);
//pointer to the string after not a copy of the string
CodePudding user response:
Because a and c are pointing to a read-only data segment, and strcpy is to write the first parameter to point to area, so there will be a period of error,And d is an array, d point position is to be able to read and write operations,
CodePudding user response:
char * a="hello segment";
Main. CPP: 8:15: warning: deprecated conversion from a string constant to "char *" [- Wwrite - strings]
Char * a="hello segment";
Now compiler in most cases can remind you this is problematic,
Shape constants on the surface of the words (the literal value), the C/C + + standard is the static storage duration, but there were no rules must be placed in the memory of what position,
For pointer, generally in the text segment or the location of the other read - only, you can't change its value;
But the array in the writable place commonly, can change, so the array used to define a variable string is a little skill,
But even if you use to create a change in the form of an array of strings, this also depends on the use of the platform or system (but normally is ok)
CodePudding user response:
From a to b, c and d values can be seen, a and c is together, in the constant section of the program memory 'and d in the stack of program memory, so you can copy data to d, but not to copy data in a and c
CodePudding user response:
Char * c="efgh" point to a constant string "efgh", in constant storage area, cannot be modified,CodePudding user response:
Memory allocation is different