小编MoM*_*oe0的帖子

指向指针和strcpy的函数

#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_DoubleString_Copy函数有效,而Get_Text函数却没有?

另外为什么String_Copy …

c pointers function

2
推荐指数
1
解决办法
233
查看次数

标签 统计

c ×1

function ×1

pointers ×1