即,为什么以下工作:
char* char_array(size_t size){
return new char[size];
}
int main(){
const char* foo = "foo";
size_t len = strlen(foo);
char* bar=char_array(len);
memset(bar, 0, len+1);
}
但以下段错误:
void char_array(char* out, size_t size){
out= new char[size];
}
int main(){
const char* foo = "foo";
size_t len = strlen(foo);
char* bar;
char_array(bar, len);
memset(bar, 0, len+1);
}