C语言函数返回数组

#include "stdio.h"
/*
int* set(int a,int *c)
{
 int *b;
 b=malloc(sizeof(int)*3);
 c[0]=a;
 c[1]=1+a;
 c[2]=2+a;
 b[0]=13;
 b[1]=14;
 b[2]=15;
 return b;
}
*/
char *set(void)
{
 char *buf;
 buf=malloc(sizeof(char)*3);//创建内存区
 buf[0]=0x30;
 buf[1]=0x31;
 buf[2]=0x32;
 return buf;
}
void main(void)
{
 /*
 int b[3];
 int *c;
 int i;
// c=malloc(sizeof(int)*3);
    c=set(3,&b);
 for(i=0;i<3;i++)
  printf("b=%d\n",b[i]);
 for(i=0;i<3;i++)
  printf("a=%d\n",c[i]);
 free(c);
 */
 char *c;
 int i;
 c=set();
 for(i=0;i<3;i++)
  printf("c=%c\n",c[i]);
 free(c);//释放内存区 
}

posted @ 2014-04-30 11:55  luxiaolai  阅读(7466)  评论(0编辑  收藏  举报