Dynamic Two Dimensional Array (Matrix) – C++

// two dimensional dynamic array (matrix) in C++
	int row,col;      //no of rows and columns
	int** array;     //dynamic array
	cin>>row>>col;     //read no of rows and columns from user

//memory allocation
	array = new int* [row];
	for (int i = 0; i < row; i++)
		array[i] = new int[col];

//then initialize array
	for(int i=0;i<row;++i)
	{
		for(int j=0;j<col;++j)
		{
			array[i][j]=0;
		}
	}
Tagged

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: