By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 838 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

How does pointer arithmetic work in case of printing addresses for a 2D array ?

P: 56
For 2D arrays , Please explain below concepts :

int main()
int matrix[2][5] = {{1,2,3,4,5},{6,7,8,9,10}};
printf("%p %p %p ", matrix+1, &matrix+1, &matrix[1][0]);
return 0;

I am unable to understand how these expressions work , matrix+1 and &matrix[1][0] return same address , how's that going ? matrix gives the base address , now to it if I add 1 , it should be base address + sizeof type to which matrix is pointing which is an int since matrix holds the base address of the first element , so it should print the address of the &matrix[0][1] , which is 2 nd element .

And I am not getting how matrix+1 and &matrix+1 are different when &matrix and matrix are printing same addresses .

Please explain it briefly .
Apr 2 '17 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 2,396
Take a look at the Arrays Revealed insights article. It may answer all your questions.
Apr 3 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.