#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Get_Text(char *string);
void Get_Text_Double(char **string);
void String_Copy(char *string);
int main(void) {
char *name = malloc(10 * sizeof(char));
char *name2 = malloc(10 * sizeof(char));
char *name3 = malloc(10 * sizeof(char));
Get_Text(name);
printf("\n%s\n", name);
Get_Text_Double(&name2);
printf("\n%s\n", name2);
String_Copy(name3);
printf("\n%s\n", name3);
return 0;
}
void Get_Text(char *string) {
string = "test";
}
void Get_Text_Double(char **string) {
*string = "test2";
}
void String_Copy(char *string) {
strcpy(string, "test3");
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,为什么Get_Text_Double
和String_Copy
函数有效,而Get_Text
函数却没有?
另外为什么String_Copy …