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 .
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 .
Comment