[Solved] Dynamic Memory allocation fault
The issue is that n keeps growing, but your array does not. This code invokes undefined behavior, which thankfully caused a segfault for you: while(ch==’y’) { n++; cout<<“Enter 1 more element: “; cin>>arr[n]; cout<<“Want to enter more? “; cin>>ch; } arr has only been allocated to store n elements. Simply writing past the end will … Read more