【c語言】期望輸出str = hello world 的兩種方法

zhaoyaqian552發表於2015-05-11
// 期望輸出str = hello world 的兩種方法

#include <stdio.h>

char *GetStr(char **p)
{
	*p = "hello word";
	return *p;
}

int main()
{
	char *str = NULL;
	if (NULL != GetStr(&str))
	{
		printf("  str = %s\n",str);
	}
	return 0;
}
</pre><pre name="code" class="cpp"><img src="https://img-blog.csdn.net/20150511210800602?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />


#include <stdio.h>

char *GetStr(char *p)
{
	p = "hello word";
	return p;
}

int main()
{
char *str = NULL;
if (NULL != GetStr(str))
{
	printf("  str = %s\n", str = GetStr(str));
}
return 0;
}

相關文章