I've just read this that by pointing a pointer to the first array member, you can cycle through by adding to the pointer.
char my_array[] = "I am an array of chars";
char *my_pointer = my_array;
printf("%c\n", *my_pointer);
my_pointer++;
printf("%c", *my_pointer);
I guess this implies array members are always stored sequentially, and the space allocated is always reserved and an array's size can not be extended (because after the length it may contain other things in memory)?
Why does this work exactly? When accessing an array using a subscript, like my_array[5]
, will C only know where the array starts (i.e. my_array[0]
), and have to increase an internal pointer by 5 to return it?
I apologize if this seems obvious, but I've spent my life in high level languages and C is very interesting to me.