lundi 31 juillet 2017

What is the type of a pointer to a 2D array?

I know that the following is not correct:

int arr[2][3] = {}; //some array initialization here
int** ptr;
ptr = arr;

But I am quite surprised that the following lines actually work

int arr[2][3] = {}; //some array initialization here
auto ptr = arr;
int another_arr[2][3] = {}; //some array initialization here
ptr = another_arr;

Can anyone possibly explain what is the type assigned to ptr in the second block of code, and what happened underneath?

Aucun commentaire:

Enregistrer un commentaire