I just wanted to make a program which takes input from the user, puts it in a character array and then just prints the co-ordinates where there are Xs, pretty simple really. It didn't work, so I wrote the following code to see if it reads the array correctly, 'cause you never know. But it outputs some strange results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int x, y;
cin>>x>>y;
char pin[x][y];
for (int i=0; i<x; i++){
for (int j=0; j<y; j++)
cin>>pin[x][y];
}
for (int q=0; q<x; q++){
for(int w=0; w<y; w++){
/*if(pin[q][w] == 'X'){
cout<<"("<<q<<","<<w<<")"<<endl;
}*/
cout<<pin[q][w]<<" ";
}
cout<<endl;
}
const has the meaning read-only and in this case this is what you have to do to declare an array if you know the size of the array. If you don't know the size and that is input at run time you have a dynamic array which requires new/delete keywords and the use of pointers. I don't know whether you have reached that point in your studies.
there may be cases where the memory needs of a program can only be determined during runtime. For example, when the memory needed depends on user input. On these cases, programs need to dynamically allocate memory, for which the C++ language integrates the operators new and delete.