On Thu, Dec 2, 2010 at 6:14 PM, Ethan Dicks <ethan.dicks at gmail.com> wrote:
Looking at what's there, I'd say that it
wouldn't surprise me that
some compilers would accept it (gcc does) and some might not, but what
it's going to do is to loop 14 times, then, using i as a pointer to an
array (for which the pointer values will range from 0-13), the loop
will sequentially access the Nth element of that array, but since "N"
happens to be the fixed address of the string "Hello, World!\n", the
effective calculation will be to sequentially point to each character
in the string (0+start address, 1+start address...) and feed the
"char" at that address to putchar() which will print it to stdout.
So... it will iterate across the static string one char at a time, but
by doing the pointer math "backwards" from the traditional technique
(i.e., a fixed index to a moving array pointer). ?The end result is
"Hello, World\n" sent to stdout.
That's what I figured it was going to do, (it wouldn't be very
interesting if the answer was it would SIGSEGV) but I don't know that
I understand why the index doesn't get multiplied by the size of the
array type before being added to the pointer.
If p is int p[] then *(p + sizeof(int)*n) is the same as p[n], right?
-chuck
ps. certainly not a C expert.