c - printing the address of the array using "array name" and "address-of array name" -


someone please explain output of following code..

#include <stdio.h>      int main()     {         int arr[5];         // assume base address of arr 2000 , size of integer 32 bit         printf("%u %u", arr + 1, &arr + 1);                  return 0;     }  

also explain out when "printf" statement replaced following

1. printf("%u %u", arr + 1, &(arr + 1)); 2. printf("%u %u", arr + 1, &arr + 2); 

first of better use format specifier %p specially designed pointers instead of format specifier %u

in statement

printf("%u %u", arr + 1, &arr + 1); 

in expression arr + 1 array arr converted pointer first element. has type after conversion int * , correspondingly element points has type int. due pointer arithmetic expression arr + 1 point next element of array second element. value of pointer arr+ 1is greater value of pointerarrbysizeof( int )`

in expression &arr + 1 pointer &arr has type int ( * )[5] . element points (that array arr) has type int[5] . value of expression &arr + 1 greater value of &arr sizeof( int[5] )

as expression &(arr + 1) not compile because arr + 1 temporary object , may not take address of temporary object.


Comments