//dynamically assign int array M * N //use C int **array = NULL; array = (int **)malloc(M * sizeof(int *)); for(int i = 0; i < M; ++i) { array[i] = (int *)malloc(N * sizeof(int)); } //free the malloced memory for(int i = 0; i < M; ++i) { free(array[i]); } free(array); //use C++ int **array = NULL; array = new int *M; for(int i = 0; i < M; ++i) { array[i] = new int[N]; } //delete the new memory for(int i = 0; i < M; ++i) { delete [] array[i]; } delete []array;