In C, when we access a[i][j] using pointers why do we need the second * in *(*(a + i) + j)? Using printf() I see a + i and *(a + i) print the same value.
In C, when we access a[i][j] using pointers why do we need the second
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
a + iis a pointer to thei‘th subarray. If you dereference it, you get an lvalue to thei‘th subarray, which decays to a pointer to that array’s first element. The address of an array’s first element and that of its array is the same.The dereference is needed to make
+ jcalculate with the correct element byte-width. If you would not dereference, then instead of gettingT*you would get aT(*)[J]pointer that you addjto, which together withiadvances into memory pointing to(a + i + j)instead (advancing bysizeof(T[J])instead ofsizeof(T)).