c++ - I am stucked with this code of accessing values in 2D array using pointers -


int main() {     int a[4][2] = {1,2,3,4,5,6,7,8};     printf("%d\n",*(a[2]+1));     printf("%d\n", *(*(a + 2)+1));     getch(); } 

two-dimensional array can thought of one-dimensional array.
output of program 6 in both printf. question how printf("%d\n", *(*(a + 2)+1)); executing , how precedence of asterik * , + evaluating.

let's consider both printf calls.

a[2] in cell int[2] = {5,6}

a[2] + 1 pointer holds address of number 6 (a[2] implicitly converted pointer), after dereference 6.

a , int[4][2] array, converted pointer (after conversion holds pointer first element)

a + 2 pointer holds address of pointer number 5

*(a + 2) pointer holds address of number 5

*(a + 2) + 1 pointer holds address of number 6

*(*(a + 2) + 1) number 6

edit:

sorry, wrong statements. take account comments , need add in above example lvalue expression of array type implicitly converted pointer first element.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -