0

I have a conflict in this code

 `int main(){
int arr[3][4]={1,2,3,4,
           4,3,2,1,
           7,8,9,0};


 printf("%x %x %x \n",arr,arr+1,&arr+1);
 return 0;}`

The output appears to me as follows: 9278fc40 9278fc50 9278fc70

what is the difference between arr+1 , &arr+1 : I didn't get the relation

Could anyone help please

Eman
  • 111
  • 1
  • 4
  • 14
  • possible duplicate of [Is array name a pointer in C?](http://stackoverflow.com/questions/1641957/is-array-name-a-pointer-in-c) – Alessandro Da Rugna Jan 31 '15 at 19:26
  • 2
    there's no "address of address of array" in this question anywhere. It may be helpful for you to know that arrays decay (are implicitly converted) into a pointer to their first element in many cases. Here, passing `arr` to the function will actually pass a pointer to its first element (`&arr[0]`). `arr + 1` is no different: it will result in `&arr[1]`. Now `&arr + 1` is a different beast – as the operand of unary `&`, the array does not decay into a pointer, so what `&arr` means is: a pointer-to-2D-array, or `int (*)[3][4]`. Now I guess you can figure out the rest. – The Paramagnetic Croissant Jan 31 '15 at 19:28

1 Answers1

0

For the two first parameters, you are printing the memory addresses of the int values arr[0][0], arr[0][1]. &arr + 1 is different. The + 1 here iterates the column. So &arr + 1 actually points to the memory address of the first int of the second column.

sandman
  • 119
  • 7
  • You're incorrect on the second and third analysis, and only partially correct on the first. The first yields the address of `arr[0]`, which *then* converts to a pointer that yields the address of `arr[0][0]`. The second converts to a pointer addressing `arr[1]`, which then converts to a pointer addressing `arr[1][0]`. Finally, `&arr + 1` points to the first `int[3][4]` *after* `arr` (of which there is none). The last expression yields an address that falls *nowhere* in the defined region of the `arr` array of arrays. – WhozCraig Jan 31 '15 at 22:40
  • Dang! You are so right! What was I thinking. After your post I went to check &arr + 1 with the debugger just to make sure. You should write this (I mean your comment) as a correct answer. – sandman Feb 01 '15 at 00:58