+ 1

int N , M; cout << "ENTER N M: cin >> N >> int **p = new int *[N] for(int i = 0; i < N; i++); P[i] = new int [M]; what is it means? i dont understand pointers of this code. please explain

pointers to pointers

11th Aug 2016, 7:28 AM
mirbek
2 odpowiedzi
+ 2
before begin - errors: cout << "ENTER N M: "; cin >> N; int **p = new int *[N]; for(int i = 0; i < N; i++) p[i] = new int [M]; and it means that you declare 2d array p [N][M]. Because the array is a set of pointers. When creating 2D array, it means creating an array of pointers to pointers, and for each pointer created new array again. and if should go to the element for example p [3][4] it means that you go to value that saved in such pointer *(*(p+3)+4)
12th Aug 2016, 5:59 AM
Dmytro Petrenko
Dmytro Petrenko - avatar
+ 1
here p is pointer to pointer but actually it pointer of multidimensional array p[i] is assigned as pointer to one 1dimentional array and for such N times so it is forming an 2d array
12th Aug 2016, 3:48 AM
Swapnil Dewalkar
Swapnil Dewalkar - avatar