Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
void cpy(char *s, char *t) { while((*s = *t) != '\0') { s++; t++; } } void main() { char *x; char *y; x="abc"; y="zzz"; cpy(x,y); }
这个功能有什么问题?*s=*t 部分错了吗?总是说“访问冲突写入位置”...
您在配额中指定的字符串是常量字符串并存储在只读内存中。所以之后
x = "abc"
x 指向只读内存区域。当您尝试使用 cpy 在那里写入时,您会遇到异常。