C语言:合并数组

来源:互联网 发布:矿用u型钢支架数据 编辑:程序博客网 时间:2024/06/05 22:32

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
0 0
原创粉丝点击