Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yeah, that's how pointer arithmetic works. Adding an int and a pointer assumes an array and gives you a pointer to the nth element in that direction (which had better exist, for your sake). char pointers can be used for byte offsets if a byte is a char on your platform (and it's been quite a while since that wasn't true).

You can also subtract two pointers into the same array and get the distance (in elements, not bytes). a[b - a] == b.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: