本文主要是介绍C语言的指针函数(小测),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
char * test(){
return "hello";
}
char * test2(){///Users/lanqs/Desktop/c语言学习/谭启宏-C-9/谭启宏-C-9/main.c:23:12: Address of stack memory associated with local variable 'string' returned
// char string[20] = "HELLO";
// char * string = "HELLO";char * string = malloc(20);*string ='b';*(string +1) ='a';
// free(string);//(有木有这一句后面都没得输出,eee 这一句是对内存的管理不能及时清理,所以应该写在下面)return string;//直接赋值第二个元素不会输出,因为第一个元素是'\0'
}
//test()char *temp = test();printf("temp = %s\n",temp);// temp[0]='h';//崩溃
// printf("temp = %s",temp);temp ="wrold";//指向world地址printf("temo = %s\n",temp);//test2()char *temp1 = test2();printf("temp1 = %s\n",temp1);
输出结果:
temp = hello
temo = wrold
temp1 = ba
Hello, World!
Program ended with exit code: 0
这篇关于C语言的指针函数(小测)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!