SIGSEGV error

why do I always get this error whenever I try to make a 2d array using dynamic memory allocation?

I asked the same question on stack overflow. They said that the best way is to not allocate memory dynamically at all. I still dont understand why.

But it’s working on other IdEs