我正在尝试理解返回本地指针的函数,char数组与char指针

时间:2017-03-17 20:33:49

标签: c

我的输出为"pqrs",但我的理解是我们无法返回本地指针。我开始认为,因为char *t = "pqrs"是字符串文字并且它将在只读存储区中,所以我们可以返回本地指针 - 但不确定我的理解是否正确

#include <stdio.h>
#include <string.h>

char *t(char *s1)
{
    char *t = "pqrs";
    s1 = "fdsa";
    return t;
}

int main()
{
    char *s = "abcde";
    s = t(s);
    printf("%s \n",s);    
    return 0;
}

0 个答案:

没有答案
相关问题