c 语言数组和指针传参对比 古城微笑少年丶 2023-06-18 08:56 1阅读 0赞 1,函数传参静态数据,指针的对比: #include<stdio.h> //数组 char* array_return() { char array[] = "hello word"; printf("array = %p\n",array); return array; } //静态数组 char* static_array_return() { static char static_array[] = "hello world"; printf("static_array = %p\n",static_array); return static_array; } //栈指针 char* pointer_return() { char *pointer = "hello word"; printf("pointer = %p\n",pointer); return pointer; } int main() { char *s1 = NULL; char *s2 = NULL; char *s3 = NULL; s1 = array_return(); s2 = static_array_return(); s3 = pointer_return(); printf("array_return= %s\n",s1); printf("static_array_return= %s\n",s2); printf("pointer_return= %s\n",s3); return 0; } 栈区数据是不能实现传递的:栈区数据是个局部变量,只是把字符串"hello word!"进行了拷贝,该局部变量是存放在栈中的,当函数退出时
还没有评论,来说两句吧...