Why next code gives me stack around variable x was corrupted?
char x[1][21];
char *ch = x[1];
strcpy(ch,"12345678901234567890");
for (int i = 0; i < 20; i++)
cout << i << ": " << &x[1][i] << " " << x[1][i] << endl;
output:
0: 12345678901234567890 1
1: 2345678901234567890 2
...
It is wrong. You should write:
as
xis declared aschar x[1][21]which means0is the only valid index for first dimension.1falls out of range.