Solar wrote:JJeronimo wrote:...a pointer to a 80 chars array in C:
char myarray[80]; makes myarray a pointer to a 80 chars array (as myarray is the address of the first element of myarray[80]).
No! Nowhere in heel char myarray[80]; does create a pointer!
It creates an array, which is NOT the same thing!
It statically reserves 80 memory-neighbour chars, and makes the symbol "myarray" translate to the address of the first element...
You cannot do myarray++; because myarray is a symbol, not a pointer variable...
Your construct above creates... a pointer to the pointer to the first element?
What?! It creates a pointer to an array of 80 chars!
The "thing" that it points to is an array of 80 chars, this is, if you use an index the compiler will calculate (or make the output code calculate) the address of the corresponding *array* (and the object returned is a pointer to char).
If I do char (*myarray)[80]; and then myarray++;, the pointer's value will be incremented by 80*sizeof(char).
If I then do myarray[n], the pointer returned will be numerically equal to myarray's, but it's type would be pointer-to-char (to which I can apply another index to access any specific char), and not pointer-to-array-of-80-chars...
Did you understand?!
That's not a 4D array, that's (a pointer to?) a 3D array.
Yes, more or less...
But I wouldn't use this type of thing to access a 3D array, because that would require me to state everywhere that I'm accessing the first element of the array...
And you should get off those magic numbers.
What's the problem with magic numbers? I think they irrelevant to the problem!
JJ