1

I am trying to understand array behavior. Please see the code below. Size of int is 4.

int arr[]={10,9,8,7,6,5};

printf("\nSingle array print=> \n%u  ||  %u  ||  %u  ||  %u",
       singlearr, &singlearr, &singlearr + 1);

I am getting the output:

2293248  ||  2293248  ||  2293272

I understand the expressions "singlarr" and "&singlearr" but when I am doing "&singlearr + 1", why it is giving output as 2293272 which is 24 bytes after the address 2293248 (2293248+24) ?

infiniteLearner
  • 3,555
  • 2
  • 23
  • 32

1 Answers1

3

&arr is a pointer to an entire array. So, if we move &arr by 1 position it will point the next block of n elements. If the array base address is b, &arr+1 will be b + (n * 4)

here, n=6 and b = 2293248 so, &arr+1 = b+(n*4) = 2293248 + (6*4) = 2293272

SbrTa
  • 148
  • 13