0

If I compile the following code using gcc array and &array evaluate to the same address:

int array[10];
int main() {
    printf("0x%x, 0x%x", array, &array);
}

Why is this the case?

user2683038
  • 667
  • 6
  • 17
  • Try `sizeof(array)` vs `sizeof(&array)`, and you will see the difference, for example `array + 1 != &array + 1`. – Iharob Al Asimi Mar 15 '15 at 02:13
  • clearly ‘sizeof(array)‘ gives me 10-times the size of an integer and ‘sizeof(&array)‘ gives me the size of a pointer. But how does that answer my question? – user2683038 Mar 15 '15 at 03:36
  • 1
    You asked what the difference was. It was also noted that `array + 1 != &array + 1` because `array + 1` will do `array+sizeof(int)` at a byte level whereas `&array + 1` will do `array+sizeof(int)*N` at a byte level, where N is the number of items in the array. The types are different as well -- a fact of which you're apparently aware. –  Mar 15 '15 at 04:30

0 Answers0