i am starting homework about dynamic array, first, I have a 2 dimensional array :
int initializeInfo[3][4] ={{77,68,0,0},{96,87,89,78},{70,90,86,0}};
and use pointer to store it:
int **ptr = (int**)malloc(3*sizeof(int));
int size = 0;
for(int i =0;i<3;i++){
    addInitiazeInfo(ptr,initializeInfo[i],size);
}
here is function addInitiazeInfo:
void addInitiazeInfo(int**& ptr, int arr[],int& size){
    ptr[size] = (int*)malloc(4*sizeof(int));
    if(ptr[size] == NULL){
        return;
    }
    ptr[size] = arr;
    size++;
}
It's run OK! The 2 dimensional array is store by ptr pointer.
And I want to add new row, I think realloc is needed, then I try:
int arr[] = {3,4,5,6};
size++;            
ptr = (int**)realloc(ptr,size * sizeof( int ) );
ptr[size-1] = (int*)malloc(4*sizeof(int));
ptr[size-1] = arr;
But I think this is my trouble, the output make me hard to know how it happend:

please help me, thanks everyone
ptr[size] = arr;is doingint **ptr = (int**)malloc(3*sizeof(int));is wrong (and so is the realloc)) . BTW: C does not have references. Maybe you mean C++ ?int **ptr;, so it points to a pointer, (or to the first member of an array of pointers) So, you should allocate3 * sizeof (int*)chars for it. AND: mixing C and C++ really is a bad habit.**&it doesn't matter whether you make it work or not, your program is unreadable either way.