#include <iostream>
int* fib(int);
int main()
{
int count;
std::cout<<"enter number up to which fibonacci series is to be printed"<<std::endl;
std::cin>>count;
int *p=new int[count];
p=fib(count);
int i;
for(i<0;i<=count;i++)
std::cout<<p[i]<<std::endl;
return 0;
}
int* fib(int d)
{
int *ar=new int[d];
int p=-1,q=1,r;
int j;
for(j=0;j<=d;j++)
{
r=p+q;
ar[j]=r;
p=q;
q=r;
}
return ar;
delete ar;
}
Why am I not able to print the whole array of Fibonacci series in this way?
delete arstatement infib()is never executed as it is after return, but if it where you'd lost the data you've just computed