Could somebody explain exactly what the following C code does please? Specially the first line and the iterated line?
int * p = &my_numbers[0];
int i;
int j = 0;
for (i = 0; i < 6; i++)
{
j += *(p + (i));
}
Does the compiler (GCC) know that when I increment the iterator, that I mean by sizeof(int) / 4 bytes instead of one byte? Is this the same for every compiler? Originally I was using:
j += *(p + (i * sizeof(int)));
but that gave the wrong answer, however:
j += *(p + (i));
did give the correct answer.
What would I have to write if I wanted to increment by only a single byte? (not sure why I would want to do this, I guess maybe the strongly typed nature of the language would allow me to use char to tell the compiler maybe?).