0

Someone can explain me this code line by line?

int width, height; cin >> width >> height; char **tab = new char*[width]; for (int x = 0; x < width; x++) { tab[x] = new char[height]; }

13th Jan 2017, 2:37 AM
Kamander X
Kamander X - avatar
6 Answers
+ 6
Width and height are the input using cin. You basically allocate memory for a pointer to a pointer which is a 2d array of size width*height.
13th Jan 2017, 3:00 AM
Karl T.
Karl T. - avatar
+ 6
Because in memory that's how a 2d array is stored.
13th Jan 2017, 3:05 AM
Karl T.
Karl T. - avatar
+ 5
No problem. :)
13th Jan 2017, 3:08 AM
Karl T.
Karl T. - avatar
0
Thanks ;) But why use this double **?
13th Jan 2017, 3:03 AM
Kamander X
Kamander X - avatar
0
Because of the double array?
13th Jan 2017, 3:05 AM
Kamander X
Kamander X - avatar
0
Thank you so much
13th Jan 2017, 3:07 AM
Kamander X
Kamander X - avatar