This is a conceptual question for me to understand C better. From what I understand about C arrays, they store pointers to values which are generated in sequence as per the space allocated. So for example, if I have this code
char someCharArray[] = {'a', 'b', 'c'};
Let's say my heap doesn't have sequential 12 bits for this array, so I store pointers to the following non-sequential addresses 0x001, 0x011, 0x040
.
I know two ways of accessing values from this array as shown in this answer.
Let's say I access the second element of the array like this
char datPointer = someCharArray[1];
In this case, datPointer
will point to 0x011
because the address is stored in the array.
However, wouldn't the following code return the wrong address?
char datWrongPointer = (someCharArray + 1);
Because I'm adding sequential addresses to the starting address of someCharArray, so assuming chars are 4 bits I'll get datWrongPointer
to be 0x004
instead of what it should be? Maybe I'm misunderstanding the addition function but I'd appreciate if someone could explain it to me.