C program address increment of array and array name

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

For this code, GCC compiler return

0xbfe41348,0xbfe41348
0xbfe4134c,0xbfe41370

The first line is clear, no problem. But the second line makes me confused. The first address moves to the next int, so it is 4 bytes after arr, clear. However, for &arr+1 I thought it will point to the end of the whole array arr[10], so it should add 4*10 to the address. Do I misunderstand something?

Don't You Worry Child

What you think is right and it is done that way only.

Since &arr => 0xbfe41348 and

0xbfe41348 + 0x28(4*10 in decimal) = 0xbfe41370

I think you got confused due to addition of decimal to a hexadecimal number.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related