Loop with pointer arithmetic refuse to stay within boundary in C. Gives me segfault.
- by Fred
Hi have made this function which is made to replicate an error that I can't get past. It looks like this:
void enumerate(double *c, int size){
while(c < &c[size]){
printf("%lf\n", *c);
c++;
}
}
I have added some printf's in there and it gives me:
Adressof c: 0x100100080, Adressof c + size: 0x1001000a8
I then also print the address of c for each iteration of the loop, it reaches 0x1001000a8 but continues past this point even though the condition should be false as far as I can tell until I get a segfault. If anyone can spot the problem, please tell me, I have been staring at this for a while now.
Thanks.