I'm doing my C programming on Ubuntu Linux, and was wondering how subtraction between array names works. I have an int array, A, of 10 items, and want to do &A[6] - A. When I do this, my printed value is 6. I thought I would get the item referenced at A[6], then subtract by the item/int at A[0] (A ==> &A[0]). However, I simply get 6.
#include <stdio.h>
int main (void) {
int A[10] = {1, 1, 1, 1, 1, 1, 23, 1, 1, 1};
int x = &A[6] - A;
printf("%d\n", x);
return 0;
}
-How did it print 6? Do I have to look at the Hex addresses with GDB? Thank you.