in this code I am trying to return the address of local array(c[100]) ,complier was showing me error of returning address of local variable but when changed the datatype from int to static int it works fine.whats the reason behind this?
#include<stdio.h>
int *str_chr(char *a,char b)
{
int i,j=0;
int c[100];
for(i=0,j=0;a[i]!='\0';i++)
{
if(a[i]==b)
{
c[j]=i;
j++;
}
}
return(c);
}
int main()
{
char a[]=" tekusn pvt limited",b='i';
int *c,i;
c=str_chr(a,b);
for(i=0;c[i]!=0;printf("%c appear in %d position:\n",b,c[i]),i++);
}
0 Answer(s)