Ciao a tutti,
devo creare un programma che genera una matrice N x N dinamica. Il problema è che il mio codice funziona perfettamente per N < 5 dopodiché mi restituisce l'errore "Bus error". Sapete dirmi come mai?


Il sorgente è il seguente:
codice:
#include <iostream>
using namespace std;

int main(){
	int dim, i, j;
	int ** m = new int*[dim];
	
	
	cout << "Choose the dimension of the squared matrix: ";
	cin >> dim;
	
	
	for(i=0;i<dim;i++){
		m[i] = new int[dim];
	}
	

	
	for(i=0;i<dim;i++){ // Righe
		
		for (j=0;j<dim;j++){ // Colonne
			m[i][j] = i*dim + (j + 1);
		}
		
	
	}
	

		for(i=0;i<dim;i++){ // Righe
		
		for (j=0;j<dim;j++){ // Colonne
			cout << " " << m[i][j] << " ";
		}
		cout << endl;
	}

return 0;
}