正确程序:
int * turn_to_b(int a,int b)//进制转换
{
int *c;
c=(int *)malloc( sizeof(int)*20 );
int count=0;
for(int m=1;m<20;m++)
c[m]=0;
do{
c[++count]=a%b;
a=a/b;
}while(a!=0);
c[0]=count;
return c;
}
错误程序:
int * turn_to_b(int a,int b)//进制转换
{
int c[20];
int count=0;
for(int m=1;m<20;m++)
c[m]=0;
do{
c[++count]=a%b;
a=a/b;
}while(a!=0);
c[0]=count;
return c;
}
第二个使用int数组方式定义,不能作为int *返回