knowledge:数组的传递及返回
Demo:
#include <stdio.h>
#include <stdlib.h>
int* func(int a[],int b[]){
int* s;
s = malloc(sizeof(int)*5);
s[0] = a[0];
s[1] = a[1];
s[2] = a[2];
s[3] = b[0];
s[4] = b[1];
return s;
}
int main()
{
int i = 0 ;
int a[3] = {1,2,3};
int b[2] = {4,5};
int* s = func(a,b);
for(i = 0 ; i < 5 ; i ++){
printf("%d ",s[i]);
}
free(s);
return 0;
}
Output:
1 2 3 4 5
本文介绍了一个C语言示例,展示了如何在函数间传递数组并返回一个新的动态分配的数组。通过具体的代码实现,读者可以了解数组操作的基本过程。
1833

被折叠的 条评论
为什么被折叠?



