can't input more than 10

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

int main (){
    int x;
    int y;
    int a;
    int b;
    cout << "insert first number ";
    cin >> a;
    cout << "insert second number ";
    cin >> b;
    int asd[a][b];
    for(x=1;x<=a;x++){
                      for(y=1;y<=b;y++)asd[x][y]=x*y;
                      }
    for(x=1;x<=a;x++){
                      for(y=1;y<=b;y++)cout << x << "*" << y << "=" << asd[x][y] << " ";
                      cout << "\n";
                      }
    system("pause");
    return 0;
}

If i put in b(line12) a number major than 9 the exe crashes, while with a(line10) i can put any number and it works properly. Anyone could explain me why ?
You use memory beyond array indexes. Should be:
for(x=1;x<a;x++)
and\
for(y=1;y<b;y++)
Last edited on
thanks
That even compiles without the int being a const int, for the array indices?

Edit:
For line 13, I mean.
Last edited on
Topic archived. No new replies allowed.