Having trouble using an array that is returned by a function in C++
This is a c++ question. I have a function that generates values in an array and returns a pointer to that array. Here's the MWE code:

    int *f(size_t s)
    {
	    int *ret=new int[s];
	    for(size_t a=0;a<s;a++)
	    {
	  	ret[a]=a;
		cout << ret[a] << endl;
	    }
	    return ret;
    }

note that I have a cout line in for for loop to prove to myself that the array is being populated properly.

Now, here's my problem. I can't find the correct method of using the returned array. Here's what I've been doing:

    int main (void)
    {
     int ary_siz = 10;
     int ary[ary_siz];
     *ary = *f(ary_siz);
     cout << ary[0] << endl;
     cout << ary[2] << endl;
     cout << ary[3] << endl;
    }

The first element in ary seems to be right. The others (ary[1],ary[2]...) are not. Can anyone tell me what I'm doing wrong?

Thanks.
Having trouble using an array that is returned by a function in C++
===

This is a c++ question. I have a function that generates values in an array and returns a pointer to that array. Here's the MWE code:

    int *f(size_t s)
    {
	    int *ret=new int[s];
	    for(size_t a=0;a<s;a++)
	    {
	  	ret[a]=a;
		cout << ret[a] << endl;
	    }
	    return ret;
    }

note that I have a cout line in for for loop to prove to myself that the array is being populated properly.

Now, here's my problem. I can't find the correct method of using the returned array. Here's what I've been doing:

    int main (void)
    {
     int ary_siz = 10;
     int ary[ary_siz];
     *ary = *f(ary_siz);
     cout << ary[0] << endl;
     cout << ary[2] << endl;
     cout << ary[3] << endl;
    }

The first element in ary seems to be right. The others (ary[1],ary[2]...) are not. Can anyone tell me what I'm doing wrong?

Thanks.