This is my code.
int* compareTriplets(int a_count, int* a, int b_count, int* b, int* result_count)
{
*result_count=2;
int arr[2];
for(int i=0;i<3;i++)
{
if(a[i]>b[i])
{
arr[0]=arr[0]+1;
}
if(b[i]>a[i])
{
arr[1]=arr[1]+1;
}
}
return arr;
}
Here is the error
Declared in compareTriplets
int arr[2]
Address of stack memory associated with local variable 'arr' returned clang(-Wreturn-stack-address)
When I use static keyword and write static int arr[2], it gives me Correct answer and no error.
Is returning local variables not possible?