I've a function :
int* sumCalc(int *p1, int *p2, int n1, int n2)
{
int sum[100] = {0};// = new int[n1+n2];
for(int i = 0; i < n1+n2; ++i)
{
sum[i] = p1[i] + p2[i];
}
return sum;
}
I'm calling this function from main() by writing :
int *sum = sumCalc(p1, p2, n1, n2);
So here I'm gonna get Warning.
To remove warning I changed my int array sum[100]
as static and then I'm returning sum.
int* sumCalc(int *p1, int *p2, int n1, int n2)
{
static int sum[100] = {0};// = new int[n1+n2];
for(int i = 0; i < n1+n2; ++i)
{
sum[i] = p1[i] + p2[i];
}
return sum;
}
So is it a good practice to make the local variable static?
And if I to take the memory for array sum[100]
from the heap then also I think this error would not be there. But can you tell how use new operator here and initialize all elements of array to zero?