2 ms·
Interestingly, you can do the same in C. For example: int *x = malloc(sizeof(int)*100); x = x + 50; Then you can use negative indexes, and this is actua
by ktRolster 9y ago
Interestingly, you can do the same in C. For example:
int *x = malloc(sizeof(int)*100);
x = x + 50;
Then you can use negative indexes, and this is actually valid code:
x[-10] = 1337;
I've only had use for that one time, when I was doing some kind of graph processing and it was convenient/efficient to have the origin in the middle of the array (instead of translating on each access).
- tacostakohashi 9y agoOr even -10[x], if you're really into using a silly index.
- Iv 9y agoI read that with a combination of fascination and nausea. Well played. But actually I remember that it can occasionally be used in image processing too, when you would use a pointer to iterate through an image, I would routinely use things like dx = *(ptr+1)-*(ptr-1); which is essentially the same as dx = ptr[1] - ptr[-1];