+ 3

C++ array pointers - An output to explain

Who can explain me why this code outputs 9? int a[3][4] = {{4,8,13,9}, {1,6,9,3}, {0,2,7,10}}; cout << *(*(a+1)+2);

5th Mar 2019, 7:52 PM
Paolo De Nictolis
Paolo De Nictolis - avatar
1 Resposta
+ 9
A pointer to an array points to the first element of the array. Increasing the pointer by 1 will make it point to the second element etc. (*(a+1)) points to 1 (first element of {1,6,9,3} which is the second element in a), the +2 moves the pointer 2 elements further
5th Mar 2019, 11:44 PM
Anna
Anna - avatar