【发布时间】:2019-08-17 07:34:41
【问题描述】:
我不知道代码出了什么问题,但是出现了分段错误。
如果 l=2 且 k= 5,则输出应为 3 5
#include<stdio.h>
int* odd(int,int,int*);
int main()
{
int l,k,*count;
int o;
o=0;
printf("enter l and k");\\entering the lest and right limit\\
scanf("%d%d",&l,&k);
count= odd(l,k,&o);\\passing address of o so i can get the count of
loop using pointer\\
for(int j=0;j<=(o);j++)
printf("%d",*(count +j));
}
int* odd(int l,int k,int * o)
{
int t[10],m=0;
for(int i=l;i<=k;i++)
{
if(i/2!=0)
{
t[m]=i;
m++;
}
}
*o=m;(using pointer to get count of loop)
return(&t[0]);
}
【问题讨论】:
-
查找“如何从 C 中的函数返回数组”。
-
还记得用您的语言名称(在本例中为 c)和版本(例如 [c11])标记问题
-
问题中的代码不可能是你正在运行的代码!
-
\\ 这不是单行 cmets 表示法。应该是
//
标签: c segmentation-fault