using linux/glibc? Segfault because you damaged the link listof freed memory chunks.
bype 0-8 of a freed memory chunk contains pointers to the previous/next freed chunks. in
for (int i = 0; i < 8; i ++)
flag[i] = true;
you destroyed the link list. When you try to free the next chunk (darray), free() tries to merge the two adjacent freed chunks. As the link list is corrupted, you see a segfault.
There are two ways to avoid segfault with you wrong program:
1.
#include
using namespace std;
int main ()
{
bool * flag = new bool[16];
delete [] flag;
double * darray = new double[10];
for (int i = 0; i < 8; i ++)
flag[8+i] = true;
cout (more...)
but after
but after delete [] flag, when u try to access flag[i], it is wrong, the compiler should be aware of it