Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • return address of local variable or array

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 592
    Answer it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: