i am new to programing and i am trying to understand the two dimensional array. i wrote this code to just test my code to see if it working or not. unfortunately, i am getting a segmentation error. i know that means that something i wrote is unreadable for the compiler but i do not know what is it. because everything seems fine to me.
#include<iostream>
using namespace std;
int main(){
int col, row,i;
int **array;
cout << "How many rows?\n";
cin >> row;
cout << "How many colomns\n";
cin >> col;
cout << "!!!!!!!!!!!!";
array = new int*[row];
for (int i = 0;i<row;i++){
array[i] = new int[col];
}
cout << "!!!!!!!!!!!!";
for( i=0; i<row; i++){
int x=1;
array[0][i]= x;;
x++;
}
cout << "!!!!!!!!!!!!";
cout << array[row][col];
for(i=0; i<row; i++){
delete [] array[i];
delete [] array;
}
return 0;
}
the ERROR is: " How many rows? 3 How many colomns 3 Segmentation fault (core dumped) "
cout << array[row][col];is out of range.array[row-1][col-1]is as deep as you can go.