The important thing I didn’t know
That is directly tied to my statement.
Understanding the ‘actuality’ of how arrays work (of any dimension) is the same as knowing that important thing you didn’t know.
Actually, seeing memory as a one-dimensional series of storage bytes is a concept as well.
Actually, it is not. Memory IS a one-dimensional series of storage bytes with linear addressing, even at the hardware level. Nothing conceptual about that.
Do you know what the difference is between:
char* const chrptr = (char*)malloc(2);
It’s really nothing more than a syntactically different declaration. Functionally, they’re identical because you can use them both in exactly the same manners. The following code is perfectly valid:
chrptr = 't';
chrptr = 0;
*array1 = 't';
*(array1+1) = 0;
Arrays ARE const pointers to a block of memory (and thus can also be treated as const pointers).
And conversely, const pointers to blocks of memory can be treated exactly like Arrays.
We do not want to know how multiplexing and adressing is handled behind the scenes
That’s unfortunate. There are definite benefit to having such knowledge. For example, if I were to give you this:
char array =
And ask you to count the number of ‘s’ in that array, an array syntax method would look something like this:
int count = 0;
for(int x = 0; x < 10; x++)
for(int y = 0; y < 10; y++)
if(array[x][y] == 's') count++;
But this, would also be a valid method, utilizing a pointer and pointer arith:
int count = 0;
char* p = (char*)array;
for(int x = 0; x < 100; x++)
if(*p++ == 's') count++;
There is more than just a syntactic difference there. The latter method utilizing pointers is about 20% faster than the former method using array indexes.