Invalid types int[int] for array subscript. Searching in a matrix
I have been trying to do a binary search in a matrix and getting this error Here's the code #include <iostream> using namespace std; int count = 0; int search(int r, int c , int key , int * matrix){ int row=0; int col=c-1; while(row<c && col>=0){ if(count>0) break; if(matrix[row][col]==key){ cout<<"Key is at "<<row<<","<<col<<endl; count++; } else if(matrix[row][col]<key){ row++; } else{ col--; } } return -1; } int main(){ int r; // Get length of row from user cout<<"Enter the row number \n"; cin>>r; int c; // Get length of col from user cout<<"Enter the col number \n"; cin>>c; int matrix[r][c]; // a matrix is defined of r x c cout<<"Enter the values of matrix \n"; // Nested loop to get the value of matrix from user for(int i=0;i<r;i++) { for(int j=0;j<c;j++){ cin>>matrix[i][j]; } } int key; cin>>key; search(r,c,key,(int*)matrix); return 0; }