How to return an array from a function and loop through it?

前端 未结 7 1641
广开言路
广开言路 2021-01-24 08:12
#include 

int* fib(int);

int main()
{
    int count;
    std::cout<<\"enter number up to which fibonacci series is to be printed\"<

        
7条回答
  •  长情又很酷
    2021-01-24 09:04

    One problem is that you allocate the array one element too short. The parameter in new[] is the number of elements, not the highest index.

    Another problem is that you allocate the array in two places, but that only creates a memory leak and doesn't affect the result.

提交回复
热议问题