• + 4 comments

    instead of writing long int *a=long int[n+1] if I write long int a[n+1]; It shows segmentation fault after test case 7. why? Explain please.

    • + 0 comments

      yes ,the same with you, i am confused

    • + 0 comments

      you aren't allocating space for a that way. He uses new to create an array on the heap. You are trying to declare it on the stack, but you can't do that with a dynamic value like 'n'

    • + 2 comments

      As per my knowledge, u can create an array to size upto 10^6 in stack and for size above it we need to create in heap so we do it dynamically. https://discuss.codechef.com/questions/28604/maximum-size-of-an-array refer this

      • + 0 comments

        Thanks @ami3443

      • + 1 comment

        for me the best explanation for the dynamic allocation was:-here!

        • + 0 comments

          Nice explanation.

    • + 0 comments

      If you have a problem understanding dynamic memory then make use of vector . It allocates memory dynamically wherein the user doesn't have to deal with pointers .

      vector arr(n); declares an array of long int of length n.